Skip to content

Commit

Permalink
fix: move fetch to next tick to get context
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 committed Feb 8, 2019
1 parent 7c35bb7 commit 73907f5
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 45 deletions.
10 changes: 2 additions & 8 deletions lib/main.dart
Expand Up @@ -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) {
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion lib/providers/settings.dart
Expand Up @@ -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;
Expand Down
47 changes: 25 additions & 22 deletions lib/screens/login.dart
Expand Up @@ -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
);
},
),
),
),
),
),
);
}
Expand Down
14 changes: 5 additions & 9 deletions lib/screens/notifications.dart
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -171,10 +171,6 @@ $key: pullRequest(number: ${item.number}) {
}
}

Future<void> _refresh() async {
await _onSwitchTab(active);
}

var textMap = {
0: 'Unread',
1: 'Paticipating',
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -244,7 +240,7 @@ $key: pullRequest(number: ${item.number}) {
onPressed: _confirm,
)
],
onRefresh: _refresh,
onRefresh: _onSwitchTab,
loading: loading,
bodyBuilder: () {
return Column(
Expand Down
5 changes: 3 additions & 2 deletions lib/screens/repo.dart
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions lib/screens/user.dart
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion lib/utils/utils.dart
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
),
Expand Down

0 comments on commit 73907f5

Please sign in to comment.