feat: settings screen
This commit is contained in:
parent
0a26509cdd
commit
0a1de91569
|
@ -17,6 +17,7 @@ class Home extends StatefulWidget {
|
|||
|
||||
class _HomeState extends State<Home> {
|
||||
int active = 0;
|
||||
// String login;
|
||||
|
||||
Widget _buildNotificationIcon(BuildContext context) {
|
||||
int count = NotificationProvider.of(context).count;
|
||||
|
@ -81,6 +82,7 @@ class _HomeState extends State<Home> {
|
|||
return MaterialApp(home: Scaffold(body: Text('a')));
|
||||
}
|
||||
|
||||
// print(settings.activeLogin);
|
||||
if (settings.activeLogin == null) {
|
||||
return MaterialApp(home: LoginScreen());
|
||||
}
|
||||
|
|
|
@ -67,6 +67,15 @@ class _SettingsProviderState extends State<SettingsProvider> {
|
|||
String activeLogin;
|
||||
StreamSubscription<Uri> _sub;
|
||||
|
||||
Future<void> 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<SettingsProvider> {
|
|||
'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<SettingsProvider> {
|
|||
} else if (Platform.isIOS) {
|
||||
theme = ThemeMap.cupertino;
|
||||
}
|
||||
// theme = ThemeMap.material;
|
||||
theme = ThemeMap.material;
|
||||
|
||||
setState(() {
|
||||
ready = true;
|
||||
|
@ -168,8 +177,16 @@ class _SettingsProviderState extends State<SettingsProvider> {
|
|||
}
|
||||
|
||||
void setActiveAccount(String login) {
|
||||
// FIXME: This is pretty tricky to trigger home screen rebuild
|
||||
setState(() {
|
||||
activeLogin = null;
|
||||
});
|
||||
nextTick(() {
|
||||
setState(() {
|
||||
activeLogin = login;
|
||||
// activeLogin = null;
|
||||
// ready = true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -212,7 +229,7 @@ class _SettingsProviderState extends State<SettingsProvider> {
|
|||
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<SettingsProvider> {
|
|||
.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;
|
||||
|
|
|
@ -55,7 +55,7 @@ class _ListScaffoldState extends State<ListScaffold> {
|
|||
}
|
||||
|
||||
Future<void> _refresh() async {
|
||||
print('list scaffold refresh');
|
||||
// print('list scaffold refresh');
|
||||
setState(() {
|
||||
error = '';
|
||||
loading = true;
|
||||
|
@ -74,7 +74,7 @@ class _ListScaffoldState extends State<ListScaffold> {
|
|||
}
|
||||
|
||||
Future<void> _loadMore() async {
|
||||
print('list scaffold load more');
|
||||
// print('list scaffold load more');
|
||||
setState(() {
|
||||
loadingMore = true;
|
||||
});
|
||||
|
|
|
@ -63,7 +63,7 @@ class _LongListScaffoldState<T, K> extends State<LongListScaffold<T, K>> {
|
|||
}
|
||||
|
||||
Future<void> _refresh() async {
|
||||
print('long list scaffold refresh');
|
||||
// print('long list scaffold refresh');
|
||||
setState(() {
|
||||
error = '';
|
||||
loading = true;
|
||||
|
@ -86,7 +86,7 @@ class _LongListScaffoldState<T, K> extends State<LongListScaffold<T, K>> {
|
|||
}
|
||||
|
||||
Future<void> _loadMore() async {
|
||||
print('long list scaffold load more');
|
||||
// print('long list scaffold load more');
|
||||
setState(() {
|
||||
loadingMore = true;
|
||||
});
|
||||
|
|
|
@ -23,6 +23,7 @@ class _LoginScreenState extends State<LoginScreen> {
|
|||
children: settings.githubAccountMap.entries.map<Widget>((entry) {
|
||||
return Link(
|
||||
beforeRedirect: () {
|
||||
// Navigator.of(context).pop();
|
||||
settings.setActiveAccount(entry.key);
|
||||
},
|
||||
child: Container(
|
||||
|
|
|
@ -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<SettingsScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var settings = SettingsProvider.of(context);
|
||||
|
||||
return SimpleScaffold(
|
||||
title: Text('Settings'),
|
||||
bodyBuilder: () {
|
||||
return Text('body');
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
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');
|
||||
},
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -158,6 +158,13 @@ class _UserScreenState extends State<UserScreen> {
|
|||
material: false,
|
||||
fullscreenDialog: true,
|
||||
),
|
||||
actions: <Widget>[
|
||||
Link(
|
||||
iconButton: Icon(Icons.settings),
|
||||
screenBuilder: (_) => SettingsScreen(),
|
||||
fullscreenDialog: true,
|
||||
),
|
||||
],
|
||||
bodyBuilder: (payload) {
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<TableViewItem> items;
|
||||
|
||||
TableView({this.title, this.items});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(top: 30),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
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<Widget> 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()),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue