1
0
mirror of https://github.com/git-touch/git-touch synced 2025-02-22 14:27:46 +01:00

fix: move fetch to next tick to get context

This commit is contained in:
Rongjian Zhang 2019-02-08 10:48:25 +08:00
parent 7c35bb7ffb
commit 73907f51b4
7 changed files with 45 additions and 45 deletions

View File

@ -86,11 +86,7 @@ class _HomeState extends State<Home> {
case ThemeMap.cupertino: case ThemeMap.cupertino:
return CupertinoApp( return CupertinoApp(
home: CupertinoTheme( home: CupertinoTheme(
data: CupertinoThemeData( data: CupertinoThemeData(),
// brightness: Brightness.dark,
// barBackgroundColor: Color.fromRGBO(0x24, 0x29, 0x2e, 1),
// primaryColor: Color(0xff24292e),
),
child: CupertinoTabScaffold( child: CupertinoTabScaffold(
tabBar: CupertinoTabBar(items: _buildNavigationItems()), tabBar: CupertinoTabBar(items: _buildNavigationItems()),
tabBuilder: (context, index) { tabBuilder: (context, index) {
@ -103,9 +99,7 @@ class _HomeState extends State<Home> {
); );
default: default:
return MaterialApp( return MaterialApp(
theme: ThemeData( theme: ThemeData(),
// primaryColor: Colors.black87,
),
home: Scaffold( home: Scaffold(
// appBar: AppBar(title: Text('Home')), // appBar: AppBar(title: Text('Home')),
body: _buildScreen(active), body: _buildScreen(active),

View File

@ -148,7 +148,7 @@ class _SettingsProviderState extends State<SettingsProvider> {
} else if (Platform.isIOS) { } else if (Platform.isIOS) {
theme = ThemeMap.cupertino; theme = ThemeMap.cupertino;
} }
theme = ThemeMap.material; // theme = ThemeMap.material;
setState(() { setState(() {
ready = true; ready = true;

View File

@ -13,30 +13,33 @@ class _LoginScreenState extends State<LoginScreen> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
var settings = SettingsProvider.of(context); var settings = SettingsProvider.of(context);
List<Widget> children =
settings.githubAccountMap.entries.map<Widget>((entry) {
return RaisedButton(
child: Text(entry.key),
onPressed: () {
settings.setActiveAccount(entry.key);
},
);
}).toList();
children.add(RaisedButton(
child: Text('Login'),
onPressed: () {
var state = settings.generateRandomString();
launch(
'https://github.com/login/oauth/authorize?client_id=$clientId&redirect_uri=gittouch://login&scope=user%20repo&state=$state',
forceSafariVC: false, // this makes URL Scheme work
);
},
));
return MaterialApp( return MaterialApp(
home: Scaffold( home: Scaffold(
body: Center(child: Column(children: children)), body: Container(
padding: EdgeInsets.only(top: 200),
child: Column(
children: settings.githubAccountMap.entries.map<Widget>((entry) {
return RaisedButton(
child: Text(entry.key),
onPressed: () {
settings.setActiveAccount(entry.key);
},
);
}).toList()
..add(
RaisedButton(
child: Text('Login'),
onPressed: () {
var state = settings.generateRandomString();
launch(
'https://github.com/login/oauth/authorize?client_id=$clientId&redirect_uri=gittouch://login&scope=user%20repo&state=$state',
forceSafariVC: false, // this makes URL Scheme work
);
},
),
),
),
),
), ),
); );
} }

View File

@ -32,13 +32,13 @@ class NotificationScreen extends StatefulWidget {
class NotificationScreenState extends State<NotificationScreen> { class NotificationScreenState extends State<NotificationScreen> {
int active = 0; int active = 0;
bool loading; bool loading = true;
Map<String, NotificationGroup> groupMap = {}; Map<String, NotificationGroup> groupMap = {};
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_refresh(); nextTick(_onSwitchTab);
} }
Future<Map<String, NotificationGroup>> fetchNotifications(int index) async { Future<Map<String, NotificationGroup>> fetchNotifications(int index) async {
@ -128,7 +128,7 @@ $key: pullRequest(number: ${item.number}) {
beforeRedirect: () async { beforeRedirect: () async {
await SettingsProvider.of(context) await SettingsProvider.of(context)
.putWithCredentials('/repos/$repo/notifications'); .putWithCredentials('/repos/$repo/notifications');
await _refresh(); await _onSwitchTab();
}, },
child: Icon( child: Icon(
Octicons.check, Octicons.check,
@ -171,10 +171,6 @@ $key: pullRequest(number: ${item.number}) {
} }
} }
Future<void> _refresh() async {
await _onSwitchTab(active);
}
var textMap = { var textMap = {
0: 'Unread', 0: 'Unread',
1: 'Paticipating', 1: 'Paticipating',
@ -204,7 +200,7 @@ $key: pullRequest(number: ${item.number}) {
var value = await showConfirm(context, 'Mark all as read?'); var value = await showConfirm(context, 'Mark all as read?');
if (value) { if (value) {
await SettingsProvider.of(context).putWithCredentials('/notifications'); await SettingsProvider.of(context).putWithCredentials('/notifications');
await _refresh(); await _onSwitchTab();
} }
} }
@ -244,7 +240,7 @@ $key: pullRequest(number: ${item.number}) {
onPressed: _confirm, onPressed: _confirm,
) )
], ],
onRefresh: _refresh, onRefresh: _onSwitchTab,
loading: loading, loading: loading,
bodyBuilder: () { bodyBuilder: () {
return Column( return Column(

View File

@ -8,6 +8,7 @@ import '../widgets/repo_item.dart';
import '../widgets/entry_item.dart'; import '../widgets/entry_item.dart';
import '../screens/issues.dart'; import '../screens/issues.dart';
import '../screens/pull_requests.dart'; import '../screens/pull_requests.dart';
import '../utils/utils.dart';
class RepoScreen extends StatefulWidget { class RepoScreen extends StatefulWidget {
final String owner; final String owner;
@ -22,12 +23,12 @@ class RepoScreen extends StatefulWidget {
class _RepoScreenState extends State<RepoScreen> { class _RepoScreenState extends State<RepoScreen> {
Map<String, dynamic> payload; Map<String, dynamic> payload;
String readme; String readme;
bool loading; bool loading = true;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_refresh(); nextTick(_refresh);
} }
Future queryRepo(BuildContext context) async { Future queryRepo(BuildContext context) async {

View File

@ -42,13 +42,13 @@ class UserScreen extends StatefulWidget {
} }
class _UserScreenState extends State<UserScreen> { class _UserScreenState extends State<UserScreen> {
bool loading; bool loading = true;
Map<String, dynamic> payload = {}; Map<String, dynamic> payload = {};
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_refresh(); nextTick(_refresh);
} }
Future queryUser(BuildContext context) async { Future queryUser(BuildContext context) async {

View File

@ -18,6 +18,12 @@ Color convertColor(String cssHex) {
return Color(int.parse('ff' + cssHex, radix: 16)); return Color(int.parse('ff' + cssHex, radix: 16));
} }
void nextTick(Function callback) {
Future.delayed(Duration(seconds: 0)).then((_) {
callback();
});
}
class Option<T> { class Option<T> {
final T value; final T value;
final Widget widget; final Widget widget;
@ -120,7 +126,7 @@ TextSpan createLinkSpan(BuildContext context, String text, Function handle) {
return TextSpan( return TextSpan(
text: text, text: text,
style: TextStyle( style: TextStyle(
color: Color(0xff0366d6), color: Colors.black87,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
// decoration: TextDecoration.underline, // decoration: TextDecoration.underline,
), ),