这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions lib/drawer/nav_drawer.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// ignore_for_file: library_private_types_in_public_api
// ignore_for_file: library_private_types_in_public_api, use_build_context_synchronously

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:sizer/sizer.dart';
import 'package:taskwarrior/config/app_settings.dart';
import 'package:taskwarrior/model/storage/storage_widget.dart';
Expand Down Expand Up @@ -115,10 +116,26 @@ class _NavDrawerState extends State<NavDrawer> {
buildMenuItem(
icon: Icons.settings,
text: 'Settings',
onTap: () {
onTap: () async {
bool syncOnStart = false;
bool syncOnTaskCreate = false;

///check if auto sync is on or off
final SharedPreferences prefs =
await SharedPreferences.getInstance();
setState(() {
syncOnStart = prefs.getBool('sync-onStart') ?? false;
syncOnTaskCreate =
prefs.getBool('sync-OnTaskCreate') ?? false;
});
// print(syncOnStart);
// print(syncOnTaskCreate);
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const SettingsPage(),
builder: (context) => SettingsPage(
isSyncOnStartActivel: syncOnStart,
isSyncOnTaskCreateActivel: syncOnTaskCreate,
),
),
);
},
Expand Down
57 changes: 32 additions & 25 deletions lib/views/settings/settings.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ignore_for_file: library_private_types_in_public_api
// ignore_for_file: library_private_types_in_public_api, must_be_immutable

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
Expand All @@ -8,33 +8,41 @@ import 'package:taskwarrior/config/taskwarriorcolors.dart';
import 'package:taskwarrior/widgets/pallete.dart';

class SettingsPage extends StatefulWidget {
const SettingsPage({Key? key}) : super(key: key);
SettingsPage(
{Key? key,
required this.isSyncOnStartActivel,
required this.isSyncOnTaskCreateActivel})
: super(key: key);
bool isSyncOnStartActivel;
bool isSyncOnTaskCreateActivel;

@override
_SettingsPageState createState() => _SettingsPageState();
}

class _SettingsPageState extends State<SettingsPage> {
bool syncOnStart = false;
bool syncOnTaskCreate = false;
// bool syncOnStart = false;
// bool syncOnTaskCreate = false;

checkAutoSync() async {
///check if auto sync is on or off
final SharedPreferences prefs = await SharedPreferences.getInstance();
setState(() {
syncOnStart = prefs.getBool('sync-onStart') ?? false;
syncOnTaskCreate = prefs.getBool('sync-OnTaskCreate') ?? false;
});
}
// checkAutoSync() async {
// ///check if auto sync is on or off
// final SharedPreferences prefs = await SharedPreferences.getInstance();
// setState(() {
// syncOnStart = prefs.getBool('sync-onStart') ?? false;
// syncOnTaskCreate = prefs.getBool('sync-OnTaskCreate') ?? false;
// });
// }

@override
void initState() {
super.initState();
checkAutoSync();
}
// @override
// void initState() {
// super.initState();
// checkAutoSync();
// }

@override
Widget build(BuildContext context) {
// syncOnStart = widget.isSyncOnStartActivel;
// syncOnTaskCreate = widget.isSyncOnTaskCreateActivel;
return Scaffold(
appBar: AppBar(
centerTitle: false,
Expand Down Expand Up @@ -90,18 +98,18 @@ class _SettingsPageState extends State<SettingsPage> {
),
),
trailing: Switch(
value: syncOnStart,
value: widget.isSyncOnStartActivel,
onChanged: (bool value) async {
setState(() {
syncOnStart = !syncOnStart;
widget.isSyncOnStartActivel = value;
});

final SharedPreferences prefs =
await SharedPreferences.getInstance();
await prefs.setBool('sync-onStart', syncOnStart);
await prefs.setBool('sync-onStart', value);
}),
),
const Divider(), // Add a divider between settings
const Divider(),
ListTile(
title: Text(
'Sync on Task Create',
Expand All @@ -119,18 +127,17 @@ class _SettingsPageState extends State<SettingsPage> {
),
),
trailing: Switch(
value: syncOnTaskCreate,
value: widget.isSyncOnTaskCreateActivel,
onChanged: (bool value) async {
setState(() {
syncOnTaskCreate = !syncOnTaskCreate;
widget.isSyncOnTaskCreateActivel = value;
});

final SharedPreferences prefs =
await SharedPreferences.getInstance();
await prefs.setBool('sync-OnTaskCreate', syncOnTaskCreate);
await prefs.setBool('sync-OnTaskCreate', value);
}),
),
// Add more settings here
],
),
);
Expand Down