Some checks are pending
Flutter CI / build (push) Waiting to run
Co-authored-by: aider (ollama_chat/7b) <aider@aider.chat>
27 lines
739 B
Dart
27 lines
739 B
Dart
import 'package:flutter/material.dart';
|
|
import 'package:sqflite/sqflite.dart';
|
|
import 'db_helper.dart';
|
|
import 'product.dart';
|
|
|
|
class ProductProvider with ChangeNotifier {
|
|
List<Product> _products = [];
|
|
|
|
List<Product> get products => _products;
|
|
|
|
Future<void> fetchProducts() async {
|
|
final db = await DbHelper().database;
|
|
final List<Map<String, dynamic>> maps = await db.query('products');
|
|
_products = List.generate(maps.length, (i) {
|
|
return Product.fromMap(maps[i]);
|
|
});
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> addProduct(Product product) async {
|
|
final db = await DbHelper().database;
|
|
await db.insert('products', product.toMap());
|
|
fetchProducts();
|
|
}
|
|
|
|
// 追加の CRUD メソッドを実装
|
|
}
|