simple dbhelper with Isar
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'pages/dashboard_page.dart';
|
import 'pages/dashboard_page.dart';
|
||||||
|
import 'services/dbhelper.dart';
|
||||||
|
|
||||||
void main() {
|
void main() async {
|
||||||
|
await DbHelper.init();
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,18 @@
|
|||||||
|
import 'package:isar/isar.dart';
|
||||||
|
|
||||||
|
part 'todo.g.dart';
|
||||||
|
|
||||||
|
@collection
|
||||||
class Todo {
|
class Todo {
|
||||||
|
final int id;
|
||||||
final String title;
|
final String title;
|
||||||
final String description;
|
final String description;
|
||||||
final DateTime createdAt;
|
final DateTime createdAt;
|
||||||
|
|
||||||
Todo({
|
Todo({
|
||||||
|
required this.id,
|
||||||
required this.title,
|
required this.title,
|
||||||
required this.description,
|
this.description = '',
|
||||||
required this.createdAt,
|
DateTime? createdAt,
|
||||||
});
|
}) : createdAt = createdAt ?? DateTime.now();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1,16 @@
|
|||||||
class DbHelper {}
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:isar/isar.dart';
|
||||||
|
|
||||||
|
import '../models/todo.dart';
|
||||||
|
|
||||||
|
class DbHelper {
|
||||||
|
static late Isar _isar;
|
||||||
|
|
||||||
|
static init() async {
|
||||||
|
final dir = await getApplicationDocumentsDirectory();
|
||||||
|
_isar = Isar.open(
|
||||||
|
schemas: [TodoSchema],
|
||||||
|
directory: dir.path,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user