Error: Unhandled Exception: MissingPluginException(No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider).
this my code.
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
class GetStoragePage extends StatefulWidget {
const GetStoragePage({super.key});
@override
State<GetStoragePage> createState() => _GetStoragePageState();
}
class _GetStoragePageState extends State<GetStoragePage> {
var data = GetStorage();
var name = '123456';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Get Storage Demo')),
body: Center(
child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
Text(
name,
style: const TextStyle(fontSize: 30),
),
const SizedBox(height: 50),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () {
data.write('name', 'John');
Get.snackbar('Seved', 'Data Save Successfully');
},
child: const Text("write")),
ElevatedButton(
onPressed: () {
data.read('name');
},
child: const Text("read"))
],
),
]),
),
);
}
}
How to solve error, give advice.
2
Answers
you have to initialize the getStorage before using it.
Usually, we call it before the run app function in the main.dart file,
like this,
Your issue belongs to this package path_provider. I mean, this package is responsible for that error.
So, now you’ve to confirm that you’ve implemented that package as a direct dependency in the pubspec.yaml file. Ensure you’ve been using the latest version from the pub dev site.
Now stop the project (if running) & open your project in the terminal window & Lastly, execute the below-mentioned commands one by one: