diff --git a/lib/main.dart b/lib/main.dart index c3f6158..71dafd1 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -17,6 +17,7 @@ class Home extends StatefulWidget { class _HomeState extends State { int active = 0; + // String login; Widget _buildNotificationIcon(BuildContext context) { int count = NotificationProvider.of(context).count; @@ -81,6 +82,7 @@ class _HomeState extends State { return MaterialApp(home: Scaffold(body: Text('a'))); } + // print(settings.activeLogin); if (settings.activeLogin == null) { return MaterialApp(home: LoginScreen()); } diff --git a/lib/providers/settings.dart b/lib/providers/settings.dart index 087ad84..0a5fc74 100644 --- a/lib/providers/settings.dart +++ b/lib/providers/settings.dart @@ -67,6 +67,15 @@ class _SettingsProviderState extends State { String activeLogin; StreamSubscription _sub; + Future setTheme(int _theme) async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + + theme = _theme; + await prefs.setInt('theme', theme); + + setState(() {}); + } + get token { if (activeLogin == null) { return null; @@ -108,7 +117,7 @@ class _SettingsProviderState extends State { 'state': randomString, }), ); - print(res.body); + // print(res.body); var data = json.decode(res.body); String _token = data['access_token']; @@ -157,7 +166,7 @@ class _SettingsProviderState extends State { } else if (Platform.isIOS) { theme = ThemeMap.cupertino; } - // theme = ThemeMap.material; + theme = ThemeMap.material; setState(() { ready = true; @@ -168,8 +177,16 @@ class _SettingsProviderState extends State { } void setActiveAccount(String login) { + // FIXME: This is pretty tricky to trigger home screen rebuild setState(() { - activeLogin = login; + activeLogin = null; + }); + nextTick(() { + setState(() { + activeLogin = login; + // activeLogin = null; + // ready = true; + }); }); } @@ -212,7 +229,7 @@ class _SettingsProviderState extends State { final res = await http .get(prefix + url, headers: headers) .timeout(_timeoutDuration); - print(res.body); + // print(res.body); final data = json.decode(res.body); return data; } @@ -231,7 +248,7 @@ class _SettingsProviderState extends State { .put(prefix + url, headers: headers, body: body ?? {}) .timeout(_timeoutDuration); - print(res.body); + // print(res.body); // final data = json.decode(res.body); // return data; return true; diff --git a/lib/scaffolds/list.dart b/lib/scaffolds/list.dart index cf56387..35c9401 100644 --- a/lib/scaffolds/list.dart +++ b/lib/scaffolds/list.dart @@ -55,7 +55,7 @@ class _ListScaffoldState extends State { } Future _refresh() async { - print('list scaffold refresh'); + // print('list scaffold refresh'); setState(() { error = ''; loading = true; @@ -74,7 +74,7 @@ class _ListScaffoldState extends State { } Future _loadMore() async { - print('list scaffold load more'); + // print('list scaffold load more'); setState(() { loadingMore = true; }); diff --git a/lib/scaffolds/long_list.dart b/lib/scaffolds/long_list.dart index 0c5bba6..59dc808 100644 --- a/lib/scaffolds/long_list.dart +++ b/lib/scaffolds/long_list.dart @@ -63,7 +63,7 @@ class _LongListScaffoldState extends State> { } Future _refresh() async { - print('long list scaffold refresh'); + // print('long list scaffold refresh'); setState(() { error = ''; loading = true; @@ -86,7 +86,7 @@ class _LongListScaffoldState extends State> { } Future _loadMore() async { - print('long list scaffold load more'); + // print('long list scaffold load more'); setState(() { loadingMore = true; }); diff --git a/lib/screens/login.dart b/lib/screens/login.dart index 569dbb1..234a76a 100644 --- a/lib/screens/login.dart +++ b/lib/screens/login.dart @@ -23,6 +23,7 @@ class _LoginScreenState extends State { children: settings.githubAccountMap.entries.map((entry) { return Link( beforeRedirect: () { + // Navigator.of(context).pop(); settings.setActiveAccount(entry.key); }, child: Container( diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart index 4b45e41..79a49a3 100644 --- a/lib/screens/settings.dart +++ b/lib/screens/settings.dart @@ -1,5 +1,10 @@ import 'package:flutter/material.dart'; +import 'package:url_launcher/url_launcher.dart'; import '../scaffolds/simple.dart'; +import '../providers/settings.dart'; +import '../widgets/table_view.dart'; +import '../screens/repo.dart'; +import '../screens/login.dart'; class SettingsScreen extends StatefulWidget { @override @@ -9,10 +14,68 @@ class SettingsScreen extends StatefulWidget { class _SettingsScreenState extends State { @override Widget build(BuildContext context) { + var settings = SettingsProvider.of(context); + return SimpleScaffold( title: Text('Settings'), bodyBuilder: () { - return Text('body'); + return Column( + children: [ + TableView( + title: 'ACCOUNTS', + items: [ + TableViewItem( + text: 'Switch to another account', + screenBuilder: (_) => LoginScreen(), + ), + ], + ), + TableView( + title: 'THEME', + items: [ + TableViewItem( + text: 'material', + checked: settings.theme == ThemeMap.material, + onTap: () { + if (settings.theme != ThemeMap.material) { + settings.setTheme(ThemeMap.material); + } + }, + ), + TableViewItem( + text: 'cupertino', + checked: settings.theme == ThemeMap.cupertino, + onTap: () { + if (settings.theme != ThemeMap.cupertino) { + settings.setTheme(ThemeMap.cupertino); + } + }, + ), + ], + ), + TableView( + title: 'SOURCE CODE', + items: [ + TableViewItem( + text: 'pd4d10/git-touch', + screenBuilder: (_) => RepoScreen('pd4d10', 'git-touch'), + ) + ], + ), + TableView( + title: 'LICENSE', + items: [ + TableViewItem( + text: 'MIT', + onTap: () { + launch( + 'https://github.com/pd4d10/git-touch/blob/master/LICENSE'); + }, + ) + ], + ) + ], + ); }, ); } diff --git a/lib/screens/user.dart b/lib/screens/user.dart index e3f0783..998adc4 100644 --- a/lib/screens/user.dart +++ b/lib/screens/user.dart @@ -158,6 +158,13 @@ class _UserScreenState extends State { material: false, fullscreenDialog: true, ), + actions: [ + Link( + iconButton: Icon(Icons.settings), + screenBuilder: (_) => SettingsScreen(), + fullscreenDialog: true, + ), + ], bodyBuilder: (payload) { return Column( children: [ diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index 1c27cfe..10d6c3a 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -19,7 +19,8 @@ Color convertColor(String cssHex) { } void nextTick(Function callback) { - Future.delayed(Duration(seconds: 0)).then((_) { + // FIXME: + Future.delayed(Duration(milliseconds: 100)).then((_) { callback(); }); } diff --git a/lib/widgets/link.dart b/lib/widgets/link.dart index 295a6e7..2a0c56b 100644 --- a/lib/widgets/link.dart +++ b/lib/widgets/link.dart @@ -9,15 +9,17 @@ class Link extends StatelessWidget { final Color bgColor; final bool material; final bool fullscreenDialog; + final Icon iconButton; Link({ - @required this.child, + this.child, this.screenBuilder, this.beforeRedirect, this.bgColor, this.material = true, this.fullscreenDialog = false, - }); + this.iconButton, + }) : assert(child != null || iconButton != null); void _onTap(BuildContext context, int theme) { if (beforeRedirect != null) { @@ -45,6 +47,13 @@ class Link extends StatelessWidget { Widget build(BuildContext context) { var theme = SettingsProvider.of(context).theme; + if (iconButton != null) { + return IconButton( + icon: iconButton, + onPressed: () => _onTap(context, theme), + ); + } + if (!material) { return GestureDetector( child: child, diff --git a/lib/widgets/table_view.dart b/lib/widgets/table_view.dart new file mode 100644 index 0000000..38e9faf --- /dev/null +++ b/lib/widgets/table_view.dart @@ -0,0 +1,78 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/cupertino.dart'; +import 'link.dart'; + +class TableViewItem { + final String text; + final bool checked; + final void Function() onTap; + final WidgetBuilder screenBuilder; + + TableViewItem({ + this.text, + this.checked = false, + this.onTap, + this.screenBuilder, + }); +} + +class TableView extends StatelessWidget { + final String title; + final List items; + + TableView({this.title, this.items}); + + @override + Widget build(BuildContext context) { + return Container( + padding: EdgeInsets.only(top: 30), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + padding: EdgeInsets.only(left: 8), + child: Text( + title, + style: TextStyle( + color: Colors.black54, + fontSize: 15, + fontWeight: FontWeight.w500, + ), + ), + ), + Container( + decoration: BoxDecoration( + border: Border(bottom: BorderSide(color: Colors.black12)), + ), + padding: EdgeInsets.only(top: 4), + ), + ]..addAll(items.map((item) { + List children = [ + Expanded( + child: Text( + item.text, + style: TextStyle(fontSize: 18, fontWeight: FontWeight.w300), + ), + ), + ]; + if (item.checked) { + children + .add(Icon(Icons.check, color: CupertinoColors.activeBlue)); + } + + return Link( + beforeRedirect: item.onTap, + screenBuilder: item.screenBuilder, + child: Container( + decoration: BoxDecoration( + border: Border(bottom: BorderSide(color: Colors.black12)), + ), + padding: EdgeInsets.all(12), + child: Row(children: children), + ), + ); + }).toList()), + ), + ); + } +}