2020-03-19 20:58:30 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:tuple/tuple.dart';
|
2020-05-06 18:50:32 +02:00
|
|
|
|
2020-07-07 17:29:21 +02:00
|
|
|
import '../state/setting_state.dart';
|
2020-07-22 11:34:32 +02:00
|
|
|
import '../util/extension_helper.dart';
|
2020-07-08 18:18:32 +02:00
|
|
|
import '../util/custom_dropdown.dart';
|
2020-03-19 20:58:30 +01:00
|
|
|
|
|
|
|
class SyncingSetting extends StatelessWidget {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-07-02 14:58:55 +02:00
|
|
|
final s = context.s;
|
2020-03-19 20:58:30 +01:00
|
|
|
var settings = Provider.of<SettingState>(context, listen: false);
|
|
|
|
return AnnotatedRegion<SystemUiOverlayStyle>(
|
|
|
|
value: SystemUiOverlayStyle(
|
|
|
|
statusBarIconBrightness: Theme.of(context).accentColorBrightness,
|
|
|
|
systemNavigationBarColor: Theme.of(context).primaryColor,
|
|
|
|
systemNavigationBarIconBrightness:
|
|
|
|
Theme.of(context).accentColorBrightness,
|
|
|
|
),
|
|
|
|
child: Scaffold(
|
|
|
|
appBar: AppBar(
|
2020-07-02 14:58:55 +02:00
|
|
|
title: Text(s.settingsSyncing),
|
2020-03-19 20:58:30 +01:00
|
|
|
elevation: 0,
|
|
|
|
backgroundColor: Theme.of(context).primaryColor,
|
|
|
|
),
|
|
|
|
body: SingleChildScrollView(
|
|
|
|
scrollDirection: Axis.vertical,
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
Selector<SettingState, Tuple2<bool, int>>(
|
|
|
|
selector: (_, settings) =>
|
|
|
|
Tuple2(settings.autoUpdate, settings.updateInterval),
|
|
|
|
builder: (_, data, __) => Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.all(10.0),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
height: 30.0,
|
2020-07-02 14:58:55 +02:00
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 70),
|
2020-03-19 20:58:30 +01:00
|
|
|
alignment: Alignment.centerLeft,
|
2020-07-02 14:58:55 +02:00
|
|
|
child: Text(s.settingsSyncing,
|
2020-03-19 20:58:30 +01:00
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.bodyText1
|
|
|
|
.copyWith(color: Theme.of(context).accentColor)),
|
|
|
|
),
|
2020-06-12 19:56:13 +02:00
|
|
|
Padding(
|
2020-07-02 14:58:55 +02:00
|
|
|
padding: const EdgeInsets.all(5.0),
|
2020-06-12 19:56:13 +02:00
|
|
|
),
|
2020-03-19 20:58:30 +01:00
|
|
|
ListView(
|
2020-03-21 17:14:10 +01:00
|
|
|
physics: const BouncingScrollPhysics(),
|
2020-03-19 20:58:30 +01:00
|
|
|
shrinkWrap: true,
|
|
|
|
scrollDirection: Axis.vertical,
|
|
|
|
children: <Widget>[
|
|
|
|
ListTile(
|
|
|
|
onTap: () {
|
|
|
|
if (settings.autoUpdate) {
|
|
|
|
settings.autoUpdate = false;
|
|
|
|
settings.cancelWork();
|
|
|
|
} else {
|
|
|
|
settings.autoUpdate = true;
|
|
|
|
settings.setWorkManager(data.item2);
|
|
|
|
}
|
|
|
|
},
|
2020-07-02 14:58:55 +02:00
|
|
|
contentPadding: const EdgeInsets.only(
|
2020-04-22 20:10:57 +02:00
|
|
|
left: 80.0, right: 20, bottom: 10),
|
2020-07-02 14:58:55 +02:00
|
|
|
title: Text(s.settingsEnableSyncing),
|
|
|
|
subtitle: Text(s.settingsEnableSyncingDes),
|
2020-06-13 15:23:08 +02:00
|
|
|
trailing: Transform.scale(
|
|
|
|
scale: 0.9,
|
|
|
|
child: Switch(
|
|
|
|
value: data.item1,
|
|
|
|
onChanged: (boo) async {
|
|
|
|
settings.autoUpdate = boo;
|
|
|
|
if (boo)
|
|
|
|
settings.setWorkManager(data.item2);
|
|
|
|
else
|
|
|
|
settings.cancelWork();
|
|
|
|
}),
|
|
|
|
),
|
2020-03-19 20:58:30 +01:00
|
|
|
),
|
|
|
|
Divider(height: 2),
|
|
|
|
ListTile(
|
|
|
|
contentPadding:
|
2020-07-02 14:58:55 +02:00
|
|
|
const EdgeInsets.only(left: 80.0, right: 20),
|
|
|
|
title: Text(s.settingsUpdateInterval),
|
|
|
|
subtitle: Text(s.settingsUpdateIntervalDes),
|
2020-07-08 18:18:32 +02:00
|
|
|
trailing: MyDropdownButton(
|
2020-07-06 11:50:20 +02:00
|
|
|
hint: Text(s.hoursCount(data.item2)),
|
2020-03-19 20:58:30 +01:00
|
|
|
underline: Center(),
|
|
|
|
elevation: 1,
|
2020-07-08 18:18:32 +02:00
|
|
|
displayItemCount: 5,
|
2020-03-19 20:58:30 +01:00
|
|
|
value: data.item2,
|
|
|
|
onChanged: data.item1
|
2020-03-31 18:36:20 +02:00
|
|
|
? (value) async {
|
|
|
|
await settings.cancelWork();
|
2020-03-19 20:58:30 +01:00
|
|
|
settings.setWorkManager(value);
|
|
|
|
}
|
|
|
|
: null,
|
|
|
|
items: <int>[1, 2, 4, 8, 24, 48]
|
|
|
|
.map<DropdownMenuItem<int>>((e) {
|
|
|
|
return DropdownMenuItem<int>(
|
2020-07-06 11:50:20 +02:00
|
|
|
value: e, child: Text(s.hoursCount(e)));
|
2020-03-19 20:58:30 +01:00
|
|
|
}).toList()),
|
|
|
|
),
|
|
|
|
Divider(height: 2),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|