import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:provider/provider.dart'; import 'package:tuple/tuple.dart'; import '../state/settingstate.dart'; class SyncingSetting extends StatelessWidget { @override Widget build(BuildContext context) { var settings = Provider.of(context, listen: false); return AnnotatedRegion( value: SystemUiOverlayStyle( statusBarIconBrightness: Theme.of(context).accentColorBrightness, systemNavigationBarColor: Theme.of(context).primaryColor, systemNavigationBarIconBrightness: Theme.of(context).accentColorBrightness, ), child: Scaffold( appBar: AppBar( title: Text('Syncing'), elevation: 0, backgroundColor: Theme.of(context).primaryColor, ), body: SingleChildScrollView( scrollDirection: Axis.vertical, child: Column( mainAxisAlignment: MainAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ Selector>( selector: (_, settings) => Tuple2(settings.autoUpdate, settings.updateInterval), builder: (_, data, __) => Column( mainAxisAlignment: MainAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ Padding( padding: EdgeInsets.all(10.0), ), Container( height: 30.0, padding: EdgeInsets.symmetric(horizontal: 70), alignment: Alignment.centerLeft, child: Text('Syncing', style: Theme.of(context) .textTheme .bodyText1 .copyWith(color: Theme.of(context).accentColor)), ), Padding( padding: EdgeInsets.all(5.0), ), ListView( physics: const BouncingScrollPhysics(), shrinkWrap: true, scrollDirection: Axis.vertical, children: [ ListTile( onTap: () { if (settings.autoUpdate) { settings.autoUpdate = false; settings.cancelWork(); } else { settings.autoUpdate = true; settings.setWorkManager(data.item2); } }, contentPadding: EdgeInsets.only( left: 80.0, right: 20, bottom: 10), title: Text('Enable syncing'), subtitle: Text( 'Refresh all podcasts in the background to get leatest episodes'), 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: EdgeInsets.only(left: 80.0, right: 20), title: Text('Update Interval'), subtitle: Text('Default 24 hours'), trailing: DropdownButton( hint: data.item2 == 1 ? Text(data.item2.toString() + ' hour') : Text(data.item2.toString() + 'hours'), underline: Center(), elevation: 1, value: data.item2, onChanged: data.item1 ? (value) async { await settings.cancelWork(); settings.setWorkManager(value); } : null, items: [1, 2, 4, 8, 24, 48] .map>((e) { return DropdownMenuItem( value: e, child: e == 1 ? Text(e.toString() + ' hour') : Text(e.toString() + ' hours')); }).toList()), ), Divider(height: 2), ], ), ], ), ), ], ), ), ), ); } }