I'm trying to use SQLite database using the sqflite
plugin. Running the app below results in Unhandled Exception: MissingPluginException
error. Here's my code:
main.dart
:
...
late final Database database;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
database = await openDatabase(
join(await getDatabasesPath(), 'mydb.db'),
version: 1,
onCreate: (db, version) {
return db.execute('CREATE TABLE config(key TEXT PRIMARY KEY, value TEXT)');
},
);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
title: 'MyApp',
initialRoute: '/',
onGenerateRoute: (settings) => onGenerateRoute(settings),
onUnknownRoute: pageNotImplementedRoute,
);
}
}
Route? onGenerateRoute(RouteSettings settings) {
...
}
Route pageNotImplementedRoute(RouteSettings settings) {
return MaterialPageRoute<void>(...);
}
Here's the output from the run:
Launching lib\main.dart on Android SDK built for x86 64 in debug mode...
Running Gradle task 'assembleDebug'...
? Built build\app\outputs\flutter-apk\app-debug.apk.
Installing build\app\outputs\flutter-apk\app.apk...
Debug service listening on ws://127.0.0.1:56398/fJzrmThsqQA=/ws
Syncing files to device Android SDK built for x86 64...
E/flutter ( 6173): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method getDatabasesPath on channel com.tekartik.sqflite)
E/flutter ( 6173): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:154:7)
E/flutter ( 6173): <asynchronous suspension>
E/flutter ( 6173): #1 wrapDatabaseException (package:sqflite/src/exception_impl.dart:7:20)
E/flutter ( 6173): <asynchronous suspension>
E/flutter ( 6173): #2 SqfliteDatabaseFactoryMixin.getDatabasesPath (package:sqflite_common/src/factory_mixin.dart:152:20)
E/flutter ( 6173): <asynchronous suspension>
E/flutter ( 6173): #3 main (package:mymedica/main.dart:76:10)
E/flutter ( 6173): <asynchronous suspension>
E/flutter ( 6173):
Anyone has any idea what's wrong?
This error is just because the SQFLite dependency not get it's package. you should follow this steps. It's Work for me...
flutter clean
flutter pub get
And you will get your desired outcome.!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.