Skip to content
Snippets Groups Projects
Commit 09603975 authored by Florian Schindler's avatar Florian Schindler
Browse files

implemented locator service and hive

both are initialized in the main function
parent 9d0bc8bc
No related branches found
No related tags found
No related merge requests found
import 'package:flutter/material.dart';
import 'package:hive/hive.dart';
import 'package:get_it/get_it.dart';
import 'package:trackeroo/logic/models/category.dart';
import 'package:trackeroo/logic/services/app_state.dart';
import 'package:trackeroo/logic/services/categories_controller.dart';
final locator = GetIt.instance;
Future<void> setupLocatorService() async {
// open AppState box and load all entries from the box into the object and register the object in get_it
var appStateBox = await Hive.openBox('app_state_box');
Map<dynamic, dynamic> appStateMap = appStateBox.toMap();
AppState appState = AppState(
isFirstOpening: appStateMap['isFirstOpening'] ?? true
);
locator.registerLazySingleton<AppState>(() => appState);
// load categories from box and safe to list, make list available in get_it
var categoriesBox = await Hive.openBox('categories_box');
if(appState.isFirstOpening) {
// create default categories
categoriesBox.addAll([
Category(id: 0, title: 'Food & Groceries', iconCodePoint: Icons.kitchen.codePoint, colorValue: Colors.green.value),
Category(id: 1, title: 'Transport & Car', iconCodePoint: Icons.directions_bus_rounded.codePoint, colorValue: Colors.amber.value),
Category(id: 2, title: 'Healthcare & Drug Stores', iconCodePoint: Icons.health_and_safety_rounded.codePoint, colorValue: Colors.red.value),
Category(id: 3, title: 'Shopping', iconCodePoint: Icons.shopping_cart_rounded.codePoint, colorValue: Colors.blue.value),
Category(id: 4, title: 'Bars & Restaurants', iconCodePoint: Icons.local_bar_rounded.codePoint, colorValue: Colors.brown.value),
Category(id: 5, title: 'Family & Friends', iconCodePoint: Icons.people_rounded.codePoint, colorValue: Colors.cyan.value),
Category(id: 6, title: 'Leisure & Entertainment', iconCodePoint: Icons.local_activity_rounded.codePoint, colorValue: Colors.purple.value),
Category(id: 7, title: 'Media & Electronics', iconCodePoint: Icons.laptop_rounded.codePoint, colorValue: Colors.grey.value),
Category(id: 8, title: 'Education', iconCodePoint: Icons.book.codePoint, colorValue: Colors.lightGreen.value),
Category(id: 9, title: 'Household & Utilities', iconCodePoint: Icons.chair_rounded.codePoint, colorValue: Colors.orange.value),
Category(id: 10, title: 'Travel & Utilities', iconCodePoint: Icons.flight_rounded.codePoint, colorValue: Colors.teal.value),
Category(id: 11, title: 'ATM', iconCodePoint: Icons.local_atm_rounded.codePoint, colorValue: Colors.deepPurple.value)
]);
}
Map<dynamic, dynamic> categoriesMap = categoriesBox.toMap();
CategoriesController categoriesController = CategoriesController(
catBox: categoriesBox,
categories: categoriesMap
);
locator.registerLazySingleton<CategoriesController>(() => categoriesController);
}
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:trackeroo/logic/models/category.dart';
import 'package:trackeroo/logic/models/transaction.dart';
import 'package:trackeroo/logic/services/locator.dart';
import 'package:trackeroo/app.dart'; import 'package:trackeroo/app.dart';
void main() { void main() async {
runApp(const MyApp()); WidgetsFlutterBinding.ensureInitialized();
await Hive.initFlutter();
Hive.registerAdapter(TransactionAdapter());
Hive.registerAdapter(CategoryAdapter());
await setupLocatorService();
runApp(MyApp());
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment