Friday, April 24, 2026
HomeiOS Developmentandroid - easy methods to name dbhelper insert or replace or delete

android – easy methods to name dbhelper insert or replace or delete

[ad_1]

import 'dart:async';

import 'bundle:path/path.dart';
import 'bundle:sqflite/sqflite.dart';

import '../fashions/product.dart';


class DbHelper {

late Database ?_db;
 static last DbHelper occasion=DbHelper();
 Future<Database> get db async{
 if(_db==null){
   _db=await initializedb();
 }
  return _db!;
}

static Future<Database> initializedb()async {
  String dbPath = be part of(await getDatabasesPath(),"etrade.db");
  var etradeDB = await openDatabase(dbPath,model: 1,onCreate: createDb);
  return etradeDB;
}

void createDb(Database db, int model)async {
await db.execute("Create desk merchandise(id integer main key, identify textual content, description 
textual content, unitPrice integer)");
}

Future<Record<Product>> getProducts() async{
Database db = await this.db;
var outcome = await db.question("merchandise");
return Record.generate(outcome.size, (i){
  return Product.fromObject(outcome[i]);
});


}
Future<int> insert(Product product) async {
Database db = await this.db;
var outcome = await db.insert("merchandise",product.toMap());
return outcome;
}

Future<int> delete(int id) async {
var db = await this.db;
var outcome = await db.rawDelete("delete from merchandise the place id=$id");
return outcome;
}

Future<int> replace(Product product) async {
var db = await this.db;
var outcome = await db.replace("product", product.toMap(), the place: "id=?",whereArgs: 
[product.id]);
return outcome;
}

}

import 'bundle:flutter/materials.dart';
import 'bundle:flutter/providers.dart';
 import 'bundle:sqflite_demo/knowledge/dbHelper.dart';


class ProductAdd extends StatefulWidget {
@override 
State<StatefulWidget> createState() {
return ProductAddState();
}
}

class ProductAddState extends State with DbHelper{
initState() {
myAsyncInit();
}

myAsyncInit() async {
//do async stuff
}
var  Dbhelper = DbHelper;
last txtName = TextEditingController();
last txtDescription = TextEditingController();
var txtUnitPrice = TextEditingController();

@override
Widget construct(BuildContext context) {
return Scaffold(
  resizeToAvoidBottomInset: false,
  appBar: AppBar(
    title: Textual content("Yeni Ürün ekle"),
  ),
  physique: Padding(
    padding: EdgeInsets.all(30.0),
    baby: Column(
      youngsters: <Widget>[
        buildNameField(),
        buildDescriptionField(),
        buildUnitPriceField(),
        buildSaveButton()
      ],
    ),
  ),
);
}

 buildUnitPriceField() {
 return TextField(
  keyboardType: TextInputType.quantity,
  inputFormatters: <TextInputFormatter>[
    FilteringTextInputFormatter.digitsOnly
  ],
  ornament: InputDecoration(labelText: "Birim fiyatı", hintText: "20"),
  controller: txtName,
 );
}

buildNameField() {
return TextField(
  ornament: InputDecoration(labelText: "Ürün adı", hintText: "Tohum"),
  controller: txtDescription,
);
}

buildDescriptionField() {
return TextField(
  ornament: const InputDecoration(
      labelText: "Ürün açıklaması", hintText: "Domates"),
  controller: txtUnitPrice,
);
}

buildSaveButton() {
return FlatButton(
  onPressed: () {
    addProduct();
  },
  baby: const Textual content("Ekle"),
);
}

void addProduct() async {

await Dbhelper.insert;
}
}

I wish to name insert from the db helper under, the error it offers is as follows
The getter ‘insert’ is not outlined for the sort ‘Sort’. (Documentation) Attempt importing the library that defines ‘insert’, correcting the identify to the identify of an present getter, or defining a getter or discipline named ‘insert’.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments