Home > OS >  MissingPluginException(No implementation Found for method getDabasesPath on channel com.tekartik.sqf
MissingPluginException(No implementation Found for method getDabasesPath on channel com.tekartik.sqf

Time:01-27

Hello guys I made simple application use sqflite when I want to insert database it says in console MissingPluginException(No implementation Found for method getDabasesPath on channel com.tekartik.sqflite)

this is code main.dart

import 'dart:async';
import 'package:ass/sqlflite.dart';
import 'package:flutter/material.dart';

void main() async {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Home(),
      title: 'Sqlflite',
    );
  }
}

class Home extends StatefulWidget {
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  SqlDb sqlDb = SqlDb();
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Container(
        child: Column(
          children: <Widget>[
            Center(
              child: MaterialButton(
                color: Theme.of(context).primaryColor,
                child: Text(
                  'InsertData  ',
                  style: TextStyle(color: Colors.white),
                ),
                onPressed: () async {
                  int response = await sqlDb.insertData(
                      "INSERT into 'notes' ('note') VALUES ('note one')");
                  print(response);
                },
              ),
            ),
            Center(
              child: MaterialButton(
                color: Theme.of(context).primaryColor,
                child: Text(
                  'ReadData  ',
                  style: TextStyle(color: Colors.white),
                ),
                onPressed: () async {
                  List<Map> response =
                      await sqlDb.readData("SELECT * FROM notes");
                  print(response);
                },
              ),
            ),
          ],
        ),
      ),
    );
  }
}

and sqlflite.dart

import 'dart:async';
import 'package:sqflite/sqflite.dart';
import 'package:path/path.dart';

class SqlDb {
  static Database? _db;
  Future<Database?> get db async {
    if (_db == null) {
      _db = await initialDb();
      return db;
    } else {
      return _db;
    }
  }

  initialDb() async {
    var databasepath = await getDatabasesPath();
    String path = await join(databasepath, 'wael.db');
    Database mydb = await openDatabase(path,
        onCreate: _onCreate, version: 3, onUpgrade: _onUpgrade);
    return mydb;
  }

  _onUpgrade(Database db, int oldversion, int newversion) async {
    print("upgrade on =============");
  }

  _onCreate(Database db, int version) async {
    await db.execute('''
CREATE TABLE "notes"(
  "id" INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT ,
  "note" TEXT NOT NULL
)

''');
    print("create DB");
  }

  readData(String sql) async {
    Database? mydb = await db;
    List<Map> response = await mydb!.rawQuery(sql);
    return response;
  }

  insertData(String sql) async {
    Database? mydb = await db;
    int response = await mydb!.rawInsert(sql);
    return response;
  }

  updateData(String sql) async {
    Database? mydb = await db;
    int response = await mydb!.rawUpdate(sql);
    return response;
  }

  deleteData(String sql) async {
    Database? mydb = await db;
    int response = await mydb!.rawDelete(sql);
    return response;
  }
}

it doesn't make any errors in analyzer but when the emulator appears and click on insertdata button it says in console MissingPluginException(No implementation Found for method getDabasesPath on channel com.tekartik.sqflite)

CodePudding user response:

MissingPluginException occurs due to the newly added dependencies run the following commands it will work

flutter clean

flutter pub get

CodePudding user response:

i used

flutter clean

flutter pub get

but it didn't work

  • Related