added TasksProvider to MainPage
parent
175735f4b9
commit
c3fde53bec
|
@ -7,7 +7,7 @@
|
|||
},
|
||||
"relapse_categories": ["App stresst mich", "langeweile", "lunge braucht es"],
|
||||
"mood_query": {
|
||||
"days": ["Montag", "Freitag"],
|
||||
"days": ["Montag", "Donnerstag"],
|
||||
"hours": 10,
|
||||
"minutes": 30
|
||||
},
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:smoke_cess_app/pages/main_page.dart';
|
||||
import 'package:smoke_cess_app/providers/task_provider.dart';
|
||||
import 'package:smoke_cess_app/providers/tasks_provider.dart';
|
||||
import 'package:smoke_cess_app/services/notification_service.dart';
|
||||
import 'package:timezone/data/latest.dart' as tz;
|
||||
import 'globals.dart' as globals;
|
||||
|
@ -29,7 +29,7 @@ class MyApp extends StatelessWidget {
|
|||
home: MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider(create: (context) => SettingsProvider()),
|
||||
ChangeNotifierProvider(create: (context) => TaskProvider()),
|
||||
ChangeNotifierProvider(create: (context) => TasksProvider()),
|
||||
],
|
||||
child: const MyHomePage(),
|
||||
));
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:awesome_dialog/awesome_dialog.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:smoke_cess_app/providers/tasks_provider.dart';
|
||||
import 'package:smoke_cess_app/services/pages_service.dart';
|
||||
import 'package:smoke_cess_app/providers/settings_provider.dart';
|
||||
|
||||
|
@ -31,12 +32,12 @@ class MyHomePageState extends State<MyHomePage> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var settingsModel = context.watch<SettingsProvider>();
|
||||
var group = settingsModel.settings?.group;
|
||||
var tasksModel = context.watch<TasksProvider>();
|
||||
_isConfigured = settingsModel.initialized;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
'${pages.values.elementAt(_selectedIndex)['title']} ${_isConfigured ? "Gruppe $group" : ""}')),
|
||||
'${pages.values.elementAt(_selectedIndex)['title']} + ${_isConfigured ? "Gruppe ${settingsModel.settings?.group}" : ""}')),
|
||||
body: Center(
|
||||
child: SingleChildScrollView(
|
||||
child: pages.values.elementAt(_selectedIndex)['page'])),
|
||||
|
@ -45,10 +46,29 @@ class MyHomePageState extends State<MyHomePage> {
|
|||
selectedIndex: _selectedIndex,
|
||||
destinations: pages.keys.map((key) {
|
||||
return NavigationDestination(
|
||||
icon: pages[key]?['icon'] ??
|
||||
const Icon(Icons.disabled_by_default),
|
||||
icon: tasksModel.tasks[key] ?? false
|
||||
? MyToDoIcon(pages[key]?['icon'])
|
||||
: pages[key]!['icon'],
|
||||
label: pages[key]?['title']);
|
||||
}).toList()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyToDoIcon extends StatelessWidget {
|
||||
final Icon _icon;
|
||||
const MyToDoIcon(this._icon, {super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Stack(children: <Widget>[
|
||||
_icon,
|
||||
const Positioned(
|
||||
// draw a red marble
|
||||
top: 0.0,
|
||||
right: 0.0,
|
||||
child: Icon(Icons.brightness_1, size: 10.0, color: Colors.redAccent),
|
||||
)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:smoke_cess_app/models/sleep.dart';
|
||||
import 'package:smoke_cess_app/models/workout.dart';
|
||||
import 'package:smoke_cess_app/services/date_service.dart';
|
||||
import 'package:smoke_cess_app/services/pages_service.dart';
|
||||
import 'package:timezone/browser.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../models/mood.dart';
|
||||
|
||||
class TaskProvider extends ChangeNotifier {
|
||||
TaskProvider() {
|
||||
initTasks();
|
||||
}
|
||||
|
||||
void setTaksDone(Pages taskName) {
|
||||
pages[taskName]?['todo'] = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void initTasks() {
|
||||
pages.forEach((key, value) async {
|
||||
if (!value['todo']) {
|
||||
switch (key) {
|
||||
case Pages.mood:
|
||||
TZDateTime? moodToday = await getTodayMood();
|
||||
if (moodToday != null) {
|
||||
List<Mood> moodList =
|
||||
await globals.databaseService.getMoodRecords();
|
||||
Mood mood = moodList.last;
|
||||
pages[key]?['todo'] = !isSameDay(moodToday, mood.date);
|
||||
}
|
||||
break;
|
||||
case Pages.sleep:
|
||||
TZDateTime? sleepToday = await getTodayMood();
|
||||
if (sleepToday != null) {
|
||||
List<Sleep> sleepList =
|
||||
await globals.databaseService.getSleepRecords();
|
||||
Sleep sleep = sleepList.last;
|
||||
pages[key]?['todo'] = !isSameDay(sleepToday, sleep.date);
|
||||
}
|
||||
break;
|
||||
case Pages.timer:
|
||||
{
|
||||
List<Workout> workoutList =
|
||||
await globals.databaseService.getWorkoutRecords();
|
||||
Workout mood = workoutList.last;
|
||||
pages[key]?['todo'] = !isSameDay(DateTime.now(), mood.date);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
}
|
||||
}
|
||||
});
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:smoke_cess_app/models/sleep.dart';
|
||||
import 'package:smoke_cess_app/models/workout.dart';
|
||||
import 'package:smoke_cess_app/services/date_service.dart';
|
||||
import 'package:smoke_cess_app/services/pages_service.dart';
|
||||
import 'package:timezone/browser.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../models/mood.dart';
|
||||
|
||||
class TasksProvider extends ChangeNotifier {
|
||||
Map<Pages, bool> tasks = {
|
||||
Pages.mood: true,
|
||||
Pages.sleep: true,
|
||||
Pages.timer: true,
|
||||
};
|
||||
|
||||
TasksProvider() {
|
||||
initTasks();
|
||||
}
|
||||
|
||||
void setTaksDone(Pages taskName) {
|
||||
tasks[taskName] = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void initTasks() async {
|
||||
TZDateTime? moodToday = await getTodayMood();
|
||||
if (moodToday != null) {
|
||||
List<Mood> moodList = await globals.databaseService.getMoodRecords();
|
||||
if (moodList.isNotEmpty) {
|
||||
Mood mood = moodList.last;
|
||||
tasks[Pages.mood] = isSameDay(moodToday, mood.date);
|
||||
}
|
||||
} else {
|
||||
tasks[Pages.mood] = false;
|
||||
}
|
||||
TZDateTime? sleepToday = await getTodayMood();
|
||||
if (sleepToday != null) {
|
||||
List<Sleep> sleepList = await globals.databaseService.getSleepRecords();
|
||||
if (sleepList.isNotEmpty) {
|
||||
Sleep sleep = sleepList.last;
|
||||
tasks[Pages.sleep] = isSameDay(sleepToday, sleep.date);
|
||||
}
|
||||
} else {
|
||||
tasks[Pages.sleep] = false;
|
||||
}
|
||||
List<Workout> workoutList =
|
||||
await globals.databaseService.getWorkoutRecords();
|
||||
if (workoutList.isNotEmpty) {
|
||||
Workout mood = workoutList.last;
|
||||
tasks[Pages.timer] = isSameDay(DateTime.now(), mood.date);
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
|
@ -18,30 +18,25 @@ const Map<Pages, Map<String, dynamic>> pages = {
|
|||
'title': 'Stimmung',
|
||||
'page': MoodPage(),
|
||||
'icon': Icon(Icons.mood_outlined, color: Colors.black),
|
||||
'todo': false,
|
||||
},
|
||||
Pages.sleep: {
|
||||
'title': 'Schlaf',
|
||||
'page': SleepPage(),
|
||||
'icon': Icon(Icons.bedtime_outlined, color: Colors.black),
|
||||
'todo': false,
|
||||
},
|
||||
Pages.relapse: {
|
||||
Pages.timer: {
|
||||
'title': 'Timer',
|
||||
'page': IntervalTimerPage(),
|
||||
'icon': Icon(Icons.timer_outlined, color: Colors.black),
|
||||
'todo': false,
|
||||
},
|
||||
Pages.timer: {
|
||||
Pages.relapse: {
|
||||
'title': 'Rückfall',
|
||||
'page': RelapsePage(),
|
||||
'icon': Icon(Icons.smoke_free_outlined, color: Colors.black),
|
||||
'todo': false,
|
||||
},
|
||||
Pages.settings: {
|
||||
'title': 'Scanner',
|
||||
'page': ScannerPage(),
|
||||
'icon': Icon(Icons.camera_alt_outlined, color: Colors.black),
|
||||
'todo': false,
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue