101 lines
3.5 KiB
Dart
101 lines
3.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:tasktracker/Data.dart';
|
|
|
|
class NotificationSettings extends StatefulWidget {
|
|
const NotificationSettings({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
_NotificationSettingsState createState() => _NotificationSettingsState();
|
|
}
|
|
|
|
class _NotificationSettingsState extends State<NotificationSettings> {
|
|
String dropdownValue = Settings.notificationOptions[1];
|
|
|
|
bool suggestionNotification = true;
|
|
bool adaptiveNotification =true;
|
|
bool adaptiveNotificationAvailable =false;
|
|
@override void initState() {
|
|
// TODO: implement initState
|
|
super.initState();
|
|
|
|
updateSettings();
|
|
}
|
|
|
|
void updateSettings() async{
|
|
int notificationInterval= await Settings.getNotificationInterval();
|
|
bool _adaptiveNotification = await Settings.getAdaptiveNotification();
|
|
adaptiveNotificationAvailable = Settings.adaptiveNotificationAvailable();
|
|
print("adaptive available: ${adaptiveNotificationAvailable}");
|
|
setState(() {
|
|
dropdownValue=Settings.notificationOptions[notificationInterval];
|
|
adaptiveNotification = _adaptiveNotification;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(title: Text("Notification Settings")),
|
|
body: SafeArea(
|
|
child: Column(
|
|
children: [
|
|
SizedBox(
|
|
height: 10,
|
|
),
|
|
ListTile(
|
|
enabled: adaptiveNotificationAvailable,
|
|
title: Text("Adaptive Notifications"),
|
|
trailing:(adaptiveNotificationAvailable) ?Switch.adaptive(value: adaptiveNotification, onChanged: (val){
|
|
adaptiveNotification=val;
|
|
Settings.setAdaptiveNotification(val);
|
|
setState(() {
|
|
|
|
});
|
|
}) : Text("Track more data to activate this", style: TextStyle(color: Colors.red)),
|
|
subtitle: Text("Notifies you to track activities according to your past activities patterns"),
|
|
|
|
),
|
|
ListTile(
|
|
enabled: !adaptiveNotification,
|
|
title: Text("New Activity Notification"),
|
|
trailing:(adaptiveNotification) ? (Text("Adaptive")) : DropdownButton<String>(
|
|
value: dropdownValue,
|
|
icon: const Icon(Icons.arrow_downward),
|
|
elevation: 16,
|
|
underline: Container(
|
|
height: 2,
|
|
color: Colors.red,
|
|
),
|
|
onChanged: (String? newValue) {
|
|
setState(() {
|
|
Settings.setNotificationInterval(Settings.notificationOptions.indexOf(newValue!));
|
|
dropdownValue = newValue!;
|
|
});
|
|
},
|
|
items:Settings.notificationOptions.map<DropdownMenuItem<String>>((String value) {
|
|
return DropdownMenuItem<String>(
|
|
value: value,
|
|
child: Text(value),
|
|
);
|
|
}).toList(),
|
|
),
|
|
subtitle: Text("Notify you to track activities of past time"),
|
|
),
|
|
Divider(),
|
|
ListTile(
|
|
title: Text("Suggestion Notifications"), trailing:Switch.adaptive(value: suggestionNotification, onChanged: (val){
|
|
suggestionNotification=val;
|
|
setState(() {
|
|
|
|
});
|
|
}),
|
|
subtitle: Text("Notifies you about suggestions according to your data"),
|
|
|
|
)
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|