@@ -9,14 +9,14 @@ import 'package:git_touch/widgets/app_bar_title.dart';
99import 'package:git_touch/widgets/entry_item.dart' ;
1010import 'package:git_touch/widgets/label.dart' ;
1111import 'package:git_touch/widgets/language_bar.dart' ;
12- import 'package:git_touch/widgets/loading.dart' ;
1312import 'package:git_touch/widgets/mutation_button.dart' ;
1413import 'package:git_touch/widgets/markdown_view.dart' ;
1514import 'package:git_touch/widgets/repo_header.dart' ;
1615import 'package:git_touch/widgets/table_view.dart' ;
1716import 'package:github/github.dart' ;
1817import 'package:provider/provider.dart' ;
1918import 'package:git_touch/models/theme.dart' ;
19+ import 'package:tuple/tuple.dart' ;
2020import 'package:git_touch/widgets/action_button.dart' ;
2121
2222class GhRepoScreen extends StatelessWidget {
@@ -25,6 +25,16 @@ class GhRepoScreen extends StatelessWidget {
2525 final String branch;
2626 GhRepoScreen (this .owner, this .name, {this .branch});
2727
28+ Future <GhRepoRepository > _query (BuildContext context) async {
29+ var res = await context.read <AuthModel >().gqlClient.execute (GhRepoQuery (
30+ variables: GhRepoArguments (
31+ owner: owner,
32+ name: name,
33+ branchSpecified: branch != null ,
34+ branch: branch ?? '' )));
35+ return res.data.repository;
36+ }
37+
2838 String _buildWatchState (GhRepoSubscriptionState state) {
2939 switch (state) {
3040 case GhRepoSubscriptionState .IGNORED :
@@ -38,21 +48,35 @@ class GhRepoScreen extends StatelessWidget {
3848 }
3949 }
4050
51+ Future <String > _fetchReadme (BuildContext context) async {
52+ try {
53+ final res = await context
54+ .read <AuthModel >()
55+ .ghClient
56+ .repositories
57+ .getReadme (RepositorySlug (owner, name));
58+ return res.text;
59+ } catch (e) {
60+ // 404
61+ return null ;
62+ }
63+ }
64+
4165 @override
4266 Widget build (BuildContext context) {
4367 final theme = Provider .of <ThemeModel >(context);
44- return RefreshStatefulScaffold <GhRepoRepository >(
68+ return RefreshStatefulScaffold <Tuple2 < GhRepoRepository , String > >(
4569 title: AppBarTitle ('Repository' ),
4670 fetch: () async {
47- var res = await context.read <AuthModel >().gqlClient.execute (GhRepoQuery (
48- variables: GhRepoArguments (
49- owner: owner,
50- name: name,
51- branchSpecified: branch != null ,
52- branch: branch ?? '' )));
53- return res.data.repository;
71+ final rs = await Future .wait ([
72+ _query (context),
73+ _fetchReadme (context),
74+ ]);
75+
76+ return Tuple2 (rs[0 ] as GhRepoRepository , rs[1 ] as String );
5477 },
55- actionBuilder: (repo, setState) {
78+ actionBuilder: (data, setState) {
79+ final repo = data.item1;
5680 return ActionButton (
5781 title: 'Repository Actions' ,
5882 items: [
@@ -68,7 +92,9 @@ class GhRepoScreen extends StatelessWidget {
6892 ],
6993 );
7094 },
71- bodyBuilder: (repo, setState) {
95+ bodyBuilder: (data, setState) {
96+ final repo = data.item1;
97+ final readme = data.item2;
7298 final ref = branch == null ? repo.defaultBranchRef : repo.ref;
7399 final license = repo.licenseInfo? .spdxId ?? repo.licenseInfo? .name;
74100
@@ -306,30 +332,15 @@ class GhRepoScreen extends StatelessWidget {
306332 ],
307333 ],
308334 ),
309- FutureBuilder <String >(
310- future: context
311- .read <AuthModel >()
312- .ghClient
313- .repositories
314- .getReadme (RepositorySlug (owner, name))
315- .then ((file) => file.text),
316- builder: (context, snapshot) {
317- if (snapshot.connectionState == ConnectionState .waiting) {
318- return Loading ();
319- }
320- if (snapshot.hasData) {
321- return Container (
322- padding: CommonStyle .padding,
323- color: theme.palette.background,
324- child: MarkdownView (
325- snapshot.data,
326- basePaths: [owner, name, branch ?? 'master' ], // TODO:
327- ),
328- );
329- }
330- return Container ();
331- },
332- ),
335+ if (readme != null )
336+ Container (
337+ padding: CommonStyle .padding,
338+ color: theme.palette.background,
339+ child: MarkdownView (
340+ readme,
341+ basePaths: [owner, name, branch ?? 'master' ], // TODO:
342+ ),
343+ ),
333344 CommonStyle .verticalGap,
334345 ],
335346 );
0 commit comments