From 4215ce860414ed2833eb3addb9fede9fab497b43 Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Wed, 22 Jan 2020 18:43:07 +0800 Subject: [PATCH] improvement: repository languages --- lib/screens/repository.dart | 83 +++++++++++++++++++++---------------- pubspec.yaml | 1 - 2 files changed, 48 insertions(+), 36 deletions(-) diff --git a/lib/screens/repository.dart b/lib/screens/repository.dart index 3595d23..f5392cd 100644 --- a/lib/screens/repository.dart +++ b/lib/screens/repository.dart @@ -18,7 +18,6 @@ import 'package:provider/provider.dart'; import 'package:git_touch/models/theme.dart'; import 'package:tuple/tuple.dart'; import 'package:git_touch/widgets/action_button.dart'; -import 'package:charts_flutter/flutter.dart' as charts; final repositoryRouter = RouterScreen('/:owner/:name', (context, params) { if (params['ref'] == null) { @@ -60,6 +59,53 @@ class RepositoryScreen extends StatelessWidget { return str; } + Widget _buildLanguages(BuildContext context, GhRepoRepository repo) { + final theme = Provider.of(context); + return Container( + color: theme.paletteOf(context).background, + padding: CommonStyle.padding, + height: 300, + child: SingleChildScrollView( + child: Table(children: [ + for (final edge in repo.languages.edges) + TableRow(children: [ + Container( + padding: CommonStyle.padding, + child: Row(children: [ + Container( + width: 18, + height: 18, + decoration: BoxDecoration( + color: convertColor(edge.node.color), + shape: BoxShape.circle, + ), + ), + SizedBox(width: 8), + Text( + edge.node.name, + style: TextStyle( + color: theme.paletteOf(context).text, + fontSize: 18, + ), + ), + ]), + ), + Container( + padding: CommonStyle.padding, + child: Text( + '${(edge.size / repo.languages.totalSize * 100).toStringAsFixed(1)}%', + style: TextStyle( + color: theme.paletteOf(context).secondaryText, + fontSize: 18, + ), + ), + ), + ]) + ]), + ), + ); + } + @override Widget build(BuildContext context) { return RefreshStatefulScaffold>( @@ -265,40 +311,7 @@ class RepositoryScreen extends StatelessWidget { onPressed: () { showCupertinoModalPopup( context: context, - builder: (context) { - return Container( - color: theme.paletteOf(context).background, - padding: EdgeInsets.all(40), - height: 400, - child: charts.PieChart( - [ - charts.Series( - id: 'languages', - domainFn: (v, _) => v.node.name, - measureFn: (v, _) => v.size, - colorFn: (v, _) => - charts.Color.fromHex(code: v.node.color), - data: repo.languages.edges, - labelAccessorFn: (v, _) => v.node.name, - ) - ], - defaultRenderer: charts.ArcRendererConfig( - arcRendererDecorators: [ - charts.ArcLabelDecorator( - insideLabelStyleSpec: charts.TextStyleSpec( - fontSize: 20, - color: charts.Color.white, - ), - outsideLabelStyleSpec: charts.TextStyleSpec( - fontSize: 20, - color: charts.Color.black, - ), - ) - ], - ), - ), - ); - }, + builder: (context) => _buildLanguages(context, repo), ); }, child: Container( diff --git a/pubspec.yaml b/pubspec.yaml index 5d66782..0f2349e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -43,7 +43,6 @@ dependencies: # ref: patch-1 gql_link: ^0.2.0 fluro: ^1.5.1 - charts_flutter: ^0.8.1 package_info: ^0.4.0 # The following adds the Cupertino Icons font to your application.