import 'dart:convert'; import 'package:filesize/filesize.dart'; import 'package:flutter/material.dart'; import 'package:git_touch/models/auth.dart'; import 'package:git_touch/models/bitbucket.dart'; import 'package:git_touch/models/theme.dart'; import 'package:git_touch/scaffolds/refresh_stateful.dart'; import 'package:git_touch/utils/utils.dart'; import 'package:git_touch/widgets/app_bar_title.dart'; import 'package:git_touch/widgets/markdown_view.dart'; import 'package:git_touch/widgets/repo_header.dart'; import 'package:git_touch/widgets/table_view.dart'; import 'package:provider/provider.dart'; import 'package:tuple/tuple.dart'; class BbRepoScreen extends StatelessWidget { final String owner; final String name; BbRepoScreen(this.owner, this.name); @override Widget build(BuildContext context) { return RefreshStatefulScaffold>( title: AppBarTitle('Repository'), fetchData: () async { final auth = Provider.of(context); final r = await auth.fetchBbJson('/repositories/$owner/$name'); final repo = BbRepo.fromJson(r); final res = await auth.fetchBb( '/repositories/$owner/$name/src/${repo.mainbranch.name}/README.md'); final readme = res.statusCode >= 400 ? null : utf8.decode(res.bodyBytes); return Tuple2(repo, readme); }, bodyBuilder: (t, setState) { final theme = Provider.of(context); final p = t.item1; return Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ RepoHeader( avatarUrl: p.avatarUrl, avatarLink: null, owner: p.ownerLogin, name: p.slug, description: p.description, homepageUrl: p.website, ), CommonStyle.border, TableView( hasIcon: true, items: [ TableViewItem( leftIconData: Octicons.code, text: Text('Code'), rightWidget: Text(filesize(p.size)), url: '/bitbucket/$owner/$name/src/${p.mainbranch.name}', ), TableViewItem( leftIconData: Octicons.history, text: Text('Commits'), url: '/bitbucket/$owner/$name/commits/${p.mainbranch.name}', ), ], ), CommonStyle.verticalGap, if (t.item2 != null) Container( padding: CommonStyle.padding, color: theme.palette.background, child: MarkdownView(t.item2), ), CommonStyle.verticalGap, ], ); }, ); } }