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 'models/daily_entry_model.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
class DailyStatusRepository {
|
class DailyStatusModel extends ChangeNotifier {
|
||||||
DailyEntry? currentDay;
|
DailyEntry? currentDay;
|
||||||
|
|
||||||
DailyStatusRepository();
|
DailyStatusModel();
|
||||||
|
|
||||||
void logFeelingMigrainy(bool status) {
|
void logFeelingMigrainy(bool status) {
|
||||||
if (currentDay == null) {
|
if (currentDay == null) {
|
||||||
|
|
@ -22,6 +23,7 @@ class DailyStatusRepository {
|
||||||
tookPainMeds: currentDay!.tookPainMeds
|
tookPainMeds: currentDay!.tookPainMeds
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
void logTookZomig(bool status) {
|
void logTookZomig(bool status) {
|
||||||
|
|
@ -41,6 +43,7 @@ class DailyStatusRepository {
|
||||||
tookPainMeds: currentDay!.tookPainMeds
|
tookPainMeds: currentDay!.tookPainMeds
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
DateTime getCurrentDate() {
|
DateTime getCurrentDate() {
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,30 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
import 'package:intl/date_symbol_data_local.dart';
|
import 'package:intl/date_symbol_data_local.dart';
|
||||||
import 'package:migrainetracker/data_storage/daily_status_repository.dart';
|
import 'package:migrainetracker/data_storage/daily_status_repository.dart';
|
||||||
import 'navigator/view.dart';
|
import 'navigator/view.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
initializeDateFormatting("de_CH", null);
|
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 {
|
class MyApp extends StatelessWidget {
|
||||||
final DailyStatusRepository dailyStatusRepository;
|
|
||||||
const MyApp({
|
const MyApp({
|
||||||
Key? key,
|
Key? key,
|
||||||
required DailyStatusRepository dailyStatusRepository,
|
}) : super(key: key);
|
||||||
})
|
|
||||||
: this.dailyStatusRepository = dailyStatusRepository,
|
|
||||||
super(key: key);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: 'Flutter Demo',
|
title: 'Flutter Demo',
|
||||||
|
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
primarySwatch: Colors.blue,
|
primarySwatch: Colors.blue,
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue