Skip to main content

Troubleshooting

Panduan mengatasi masalah umum dalam development MStore Mobile.

🔧 Build Issues

Flutter Build Errors

Error: “Gradle build failed”

Gejala:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugResources'.
Solusi:
# Clean project
cd android
./gradlew clean
cd ..
flutter clean

# Rebuild
flutter pub get
flutter build apk --flavor development -t lib/main_development.dart

Error: “Pod install failed”

Gejala:
[!] CocoaPods could not find compatible versions for pod "Firebase/Core"
Solusi:
cd ios
rm -rf Pods Podfile.lock
pod cache clean --all
pod deintegrate
pod install --repo-update
cd ..

Error: “Native Sound Plugin not found”

Gejala:
Error: Could not resolve the package 'native_sound_plugin'
Solusi:
# Set environment variable
export NATIVE_SOUND_PLUGIN_PATH=/absolute/path/to/native_sound_plugin/ios

# Or update pubspec.yaml
# dependencies:
#   native_sound_plugin:
#     path: /absolute/path/to/native_sound_plugin

cd ios
pod install
cd ..

Code Generation Issues

Error: “Conflicting outputs”

Gejala:
[WARNING] build_runner:build_runner on lib/core/product/product_api.dart:
Conflicting outputs were detected
Solusi:
# Force regenerate
flutter pub run build_runner build --delete-conflicting-outputs

# Or use watch mode
flutter pub run build_runner watch --delete-conflicting-outputs

Error: “Part file doesn’t exist”

Gejala:
Error: Part file doesn't exist: 'product_api.g.dart'
Solusi:
# Ensure part directive exists
# In product_api.dart:
# part 'product_api.g.dart';

# Run code generation
flutter pub run build_runner build --delete-conflicting-outputs

🌐 Network Issues

API Connection Failed

Gejala:
DioException [connection error]: Connection refused
Debugging:
// Check API base URL
print('API_BASE_URL: $API_BASE_URL');

// Test with curl
curl -X GET https://dev-api.mstore.com/api/v1/products

// Check network connectivity
final connectivity = await Connectivity().checkConnectivity();
print('Connectivity: $connectivity');
Solusi:
  1. Verify .env file loaded correctly
  2. Check network connection
  3. Verify API server is running
  4. Check firewall/proxy settings

Token Refresh Failed

Gejala:
Error: Refresh token invalid or expired
Solusi:
// Clear tokens and re-login
await AuthService().logout();
await AuthService().clearTokens();

// Navigate to login
context.go('/login');

MQTT Connection Failed

Gejala:
MQTT connection failed: Connection refused
Debugging:
// Check MQTT configuration
print('MQTT_BROKER: $MQTT_BROKER');
print('MQTT_PORT: $MQTT_PORT');
print('MQTT_CLIENT_ID: $MQTT_CLIENT_ID');

// Test MQTT connection
final client = MqttServerClient(MQTT_BROKER, MQTT_CLIENT_ID);
client.port = int.parse(MQTT_PORT);
client.logging(on: true);
await client.connect(MQTT_USERNAME, MQTT_PASSWORD);
Solusi:
  1. Verify MQTT broker URL and port
  2. Check credentials
  3. Ensure network allows MQTT port (usually 1883)
  4. Check broker is running

💾 Database Issues

Isar Database Errors

Error: “Isar instance already opened”

Gejala:
IsarError: Isar instance with name 'default' is already open
Solusi:
// Close existing instance first
if (Isar.instanceNames.contains('default')) {
  final isar = Isar.getInstance('default');
  await isar?.close();
}

// Then open new instance
final isar = await Isar.open([...schemas]);

Error: “Schema mismatch”

Gejala:
IsarError: Schema version mismatch
Solusi:
# Regenerate Isar schemas
flutter pub run build_runner build --delete-conflicting-outputs

# Or delete database and recreate
# Database location:
# iOS: ~/Library/Developer/CoreSimulator/Devices/.../Documents/
# Android: /data/data/com.mstore.mobile/files/

Data Not Syncing

Debugging:
// Check local data
final products = await isar.productLocals.where().findAll();
print('Local products: ${products.length}');

// Check API data
final result = await productRepository.getProducts();
result.fold(
  (failure) => print('API Error: ${failure.message}'),
  (products) => print('API products: ${products.length}'),
);

// Check sync service
final syncService = getIt<OfflineSyncService>();
final pendingSync = await syncService.getPendingItems();
print('Pending sync: ${pendingSync.length}');
Solusi:
  1. Verify network connection
  2. Check API endpoints
  3. Review sync logic in OfflineSyncService
  4. Clear local cache and re-sync

🎨 UI Issues

Widget Not Rebuilding

Gejala: UI tidak update setelah state berubah. Debugging:
// Add logging to BLoC
@override
void onChange(Change<ProductState> change) {
  super.onChange(change);
  print('State changed: ${change.currentState} -> ${change.nextState}');
}

// Check BlocBuilder buildWhen
BlocBuilder<ProductBloc, ProductState>(
  buildWhen: (previous, current) {
    print('buildWhen: $previous != $current');
    return previous != current;
  },
  builder: (context, state) => ...,
)
Solusi:
  1. Ensure state implements Equatable properly
  2. Check buildWhen condition
  3. Verify BLoC is provided correctly
  4. Use BlocConsumer if needed

Layout Overflow

Gejala:
A RenderFlex overflowed by 123 pixels on the right.
Solusi:
// ✅ Use Expanded/Flexible
Row(
  children: [
    Expanded(child: Text('Long text...')),
    Icon(Icons.arrow_forward),
  ],
)

// ✅ Use ListView for scrollable content
ListView(
  children: [...],
)

// ✅ Wrap with SingleChildScrollView
SingleChildScrollView(
  child: Column(children: [...]),
)

Performance Issues

Gejala: UI terasa lag atau jank. Debugging:
// Enable performance overlay
void main() {
  runApp(
    MaterialApp(
      showPerformanceOverlay: true,
      home: MyApp(),
    ),
  );
}

// Use Flutter DevTools
// flutter pub global activate devtools
// flutter pub global run devtools
Solusi:
  1. Use const constructors
  2. Avoid rebuilding entire tree
  3. Use ListView.builder for long lists
  4. Optimize images (use cached_network_image)
  5. Profile with Flutter DevTools

🔐 Authentication Issues

Login Failed

Gejala:
Error: Invalid credentials
Debugging:
// Check request payload
AppLog.i('auth', 'login_attempt', meta: {
  'email': email,
  'endpoint': '$API_BASE_URL/api/v1/auth/login',
});

// Check response
final response = await authApi.login(email, password);
print('Response: ${response.data}');
Solusi:
  1. Verify email/password correct
  2. Check API endpoint URL
  3. Review backend logs
  4. Test with Postman/curl

Token Expired

Gejala:
HTTP 401: Unauthorized
Solusi:
// RefreshTokenInterceptor should handle this automatically
// If not working, check:

// 1. Verify interceptor is registered
dio.interceptors.add(RefreshTokenInterceptor(dio: dio));

// 2. Check refresh token exists
final refreshToken = await AuthService().getRefreshToken();
print('Refresh token: ${refreshToken != null}');

// 3. Manual refresh
await AuthService().silentRefreshIfNeeded();

🖨️ Printer Issues

Bluetooth Printer Not Found

Gejala:
Error: No paired Bluetooth devices found
Solusi:
// 1. Check Bluetooth permissions
// iOS: Info.plist
// <key>NSBluetoothAlwaysUsageDescription</key>
// <string>Need Bluetooth for printer</string>

// Android: AndroidManifest.xml
// <uses-permission android:name="android.permission.BLUETOOTH"/>
// <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
// <uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>

// 2. Request permissions
await Permission.bluetooth.request();
await Permission.bluetoothConnect.request();

// 3. Scan for devices
final printerService = getIt<PrinterService>();
final devices = await printerService.scanDevices();
print('Found devices: ${devices.length}');
Gejala: Receipt tidak tercetak. Debugging:
// Check printer connection
final isConnected = await printerService.isConnected();
print('Printer connected: $isConnected');

// Test print
await printerService.printTest();

// Check receipt data
print('Receipt data: ${receipt.toString()}');
Solusi:
  1. Verify printer is paired and connected
  2. Check printer has paper
  3. Verify receipt format
  4. Test with simple text first

📱 Platform-Specific Issues

iOS Issues

Error: “Signing for … requires a development team”

Solusi:
  1. Open Xcode
  2. Select project → Signing & Capabilities
  3. Select your team
  4. Enable “Automatically manage signing”

Error: “Module not found”

Solusi:
cd ios
pod deintegrate
pod install
cd ..
flutter clean
flutter run

Android Issues

Error: “Minimum SDK version”

Gejala:
Error: The plugin requires a minimum Android SDK version of 21
Solusi:
// android/app/build.gradle
android {
    defaultConfig {
        minSdkVersion 21  // Update this
        targetSdkVersion 34
    }
}

Error: “MultiDex”

Solusi:
// android/app/build.gradle
android {
    defaultConfig {
        multiDexEnabled true
    }
}

dependencies {
    implementation 'androidx.multidex:multidex:2.0.1'
}

🔍 Debugging Tools

Flutter DevTools

# Activate DevTools
flutter pub global activate devtools

# Run DevTools
flutter pub global run devtools

# Or use from VS Code
# View → Command Palette → "Dart: Open DevTools"

Logging

// Enable verbose logging
AppLog.setLevel(LogLevel.verbose);

// Log BLoC events
Bloc.observer = const AppBlocObserver();

// Log HTTP requests
dio.interceptors.add(LoggingInterceptor());

// Export logs
final logs = await AppLog.exportLogs();
await Share.shareFiles([logs]);

Network Inspector

// Use Alice for HTTP inspection
final alice = Alice(showNotification: true);
dio.interceptors.add(alice.getDioInterceptor());

// Or use Charles Proxy
// Configure proxy in device settings

🆘 Getting Help

Before Asking for Help

  1. ✅ Check this troubleshooting guide
  2. ✅ Search existing issues
  3. ✅ Review logs and error messages
  4. ✅ Try to reproduce the issue
  5. ✅ Prepare minimal reproduction code

Creating a Bug Report

## Environment
- Flutter version: 3.8.0
- Dart version: 3.8.0
- Platform: iOS 17.0 / Android 14
- Device: iPhone 15 Pro / Pixel 8

## Description
Clear description of the issue

## Steps to Reproduce
1. Open app
2. Navigate to Cashier
3. Add product to cart
4. Crash occurs

## Expected Behavior
Cart should update

## Actual Behavior
App crashes with error: ...

## Logs
[Paste relevant logs here]

## Screenshots
[Attach screenshots if applicable]

## Additional Context
Any other relevant information

Useful Commands

# Flutter doctor
flutter doctor -v

# Clean and rebuild
flutter clean && flutter pub get && flutter run

# Analyze code
flutter analyze

# Run tests
flutter test

# Check dependencies
flutter pub outdated

# Update dependencies
flutter pub upgrade

# Generate code
flutter pub run build_runner build --delete-conflicting-outputs

# Profile performance
flutter run --profile

# Build with verbose
flutter build apk --verbose

📚 Additional Resources

Next Steps


Jika masalah masih berlanjut:
  • 💬 Hubungi tim development
  • 📧 Buat issue di repository
  • 🔍 Review dengan senior developer