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

View File

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

View File

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

View File

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

View File

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

View File

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