[Flutter] drift - (5) Instance 만들어서 사용하기

Jinno·2023년 1월 13일
0

Flutter

목록 보기
14/19

1. main.dart에서 database instance 만들어서 사용

  • final database = LocalDataBase();

2. 만드었던 함수 사용

  • insert 시, Value()로 감싸서 넣어줘야 함
const DEFAULT_COLORS = [
  'F44336',
  'FF9800',
  'FFEB3B',
];

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await initializeDateFormatting();

  final database = LocalDataBase();

  final colors = await database.getCategoryColors();
  
  
  if (colors.isEmpty) {
    for (String hexCode in DEFAULT_COLORS) {
      await database.createCategoryColor(
        CategoryColorsCompanion(
          hexCode: Value(hexCode),
        ),
      );
    }
  }

  print(await database.getCategoryColors());

  runApp(MaterialApp(
    home: HomeScreen(),
  ));
}
profile
Innovation, 기록용

0개의 댓글