feat: rename DailyStatusRepository to DailyStatusModel and wrap with a ChangeNotifierProvider
This commit is contained in:
parent
88b50708c2
commit
77418d216f
2 changed files with 14 additions and 10 deletions
|
|
@ -1,9 +1,10 @@
|
|||
import 'models/daily_entry_model.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
class DailyStatusRepository {
|
||||
class DailyStatusModel extends ChangeNotifier {
|
||||
DailyEntry? currentDay;
|
||||
|
||||
DailyStatusRepository();
|
||||
DailyStatusModel();
|
||||
|
||||
void logFeelingMigrainy(bool status) {
|
||||
if (currentDay == null) {
|
||||
|
|
@ -22,6 +23,7 @@ class DailyStatusRepository {
|
|||
tookPainMeds: currentDay!.tookPainMeds
|
||||
);
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void logTookZomig(bool status) {
|
||||
|
|
@ -41,6 +43,7 @@ class DailyStatusRepository {
|
|||
tookPainMeds: currentDay!.tookPainMeds
|
||||
);
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
DateTime getCurrentDate() {
|
||||
|
|
|
|||
|
|
@ -1,29 +1,30 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:intl/date_symbol_data_local.dart';
|
||||
import 'package:migrainetracker/data_storage/daily_status_repository.dart';
|
||||
import 'navigator/view.dart';
|
||||
|
||||
void main() {
|
||||
initializeDateFormatting("de_CH", null);
|
||||
DailyStatusRepository dailyStatusRepository = DailyStatusRepository();
|
||||
DailyStatusModel dailyStatusModel = DailyStatusModel();
|
||||
|
||||
runApp(MyApp(dailyStatusRepository: dailyStatusRepository));
|
||||
runApp(
|
||||
ChangeNotifierProvider(
|
||||
create: (context) => dailyStatusModel,
|
||||
child: const MyApp(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
final DailyStatusRepository dailyStatusRepository;
|
||||
const MyApp({
|
||||
Key? key,
|
||||
required DailyStatusRepository dailyStatusRepository,
|
||||
})
|
||||
: this.dailyStatusRepository = dailyStatusRepository,
|
||||
super(key: key);
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
|
||||
theme: ThemeData(
|
||||
primarySwatch: Colors.blue,
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue