tsacdop-podcast-app-android/lib/settings/syncing.dart

126 lines
5.3 KiB
Dart
Raw Normal View History

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';
import '../util/extension_helper.dart';
import '../util/custom_dropdown.dart';
class SyncingSetting extends StatelessWidget {
@override
Widget build(BuildContext context) {
2020-07-02 14:58:55 +02:00
final s = context.s;
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),
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),
alignment: Alignment.centerLeft,
2020-07-02 14:58:55 +02:00
child: Text(s.settingsSyncing,
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
),
ListView(
physics: const BouncingScrollPhysics(),
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(
left: 80.0, right: 20, bottom: 10),
2020-07-02 14:58:55 +02:00
title: Text(s.settingsEnableSyncing),
subtitle: Text(s.settingsEnableSyncingDes),
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();
}),
),
),
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),
trailing: MyDropdownButton(
2020-07-06 11:50:20 +02:00
hint: Text(s.hoursCount(data.item2)),
underline: Center(),
elevation: 1,
displayItemCount: 5,
value: data.item2,
onChanged: data.item1
2020-03-31 18:36:20 +02:00
? (value) async {
await settings.cancelWork();
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)));
}).toList()),
),
Divider(height: 2),
],
),
],
),
),
],
),
),
),
);
}
}