From efd74ccd864bcc8ba3bebdcb7976ba9e29ce7765 Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Thu, 6 Oct 2022 15:55:35 +0800 Subject: [PATCH] refactor: replace material widgets --- lib/screens/ge_pull.dart | 84 +++++++++++++++++----------------- lib/utils/utils.dart | 2 - lib/widgets/files_item.dart | 33 ++++++++------ lib/widgets/release_item.dart | 86 ++++++++++++++++++----------------- pubspec.yaml | 2 +- 5 files changed, 105 insertions(+), 102 deletions(-) diff --git a/lib/screens/ge_pull.dart b/lib/screens/ge_pull.dart index d487d56..c935e6c 100644 --- a/lib/screens/ge_pull.dart +++ b/lib/screens/ge_pull.dart @@ -1,5 +1,5 @@ import 'package:antd_mobile/antd_mobile.dart'; -import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; import 'package:git_touch/models/auth.dart'; import 'package:git_touch/models/gitee.dart'; import 'package:git_touch/scaffolds/refresh_stateful.dart'; @@ -165,16 +165,18 @@ class GePullScreen extends StatelessWidget { children: [ Text( '+$additions', - style: const TextStyle( - color: Colors.green, + style: TextStyle( + color: AntTheme.of(context) + .colorSuccess, fontSize: 15, ), ), const SizedBox(width: 2), Text( '-$deletions', - style: const TextStyle( - color: Colors.red, + style: TextStyle( + color: AntTheme.of(context) + .colorDanger, fontSize: 15, ), ), @@ -190,46 +192,42 @@ class GePullScreen extends StatelessWidget { ), ), CommonStyle.border, - ListTileTheme( - contentPadding: EdgeInsets.zero, - child: ExpansionTile( - title: Text( - 'Commits', - style: TextStyle( - color: AntTheme.of(context).colorPrimary, - fontSize: 18, - fontWeight: FontWeight.w600, - ), - ), - children: [ - for (var commit in commits) ...[ - LinkWidget( - url: - '/gitee/$owner/$name/commits/${commit.sha}', - child: Container( - padding: const EdgeInsets.symmetric( - vertical: 8), - child: Row( - mainAxisAlignment: - MainAxisAlignment.spaceBetween, - children: [ - Text( - commit.sha!.substring(0, 7), - style: TextStyle( - color: AntTheme.of(context) - .colorPrimary, - fontSize: 17, - fontFamily: - CommonStyle.monospace, - ), + Column( + // title: Text( + // 'Commits', + // style: TextStyle( + // color: AntTheme.of(context).colorPrimary, + // fontSize: 18, + // fontWeight: FontWeight.w600, + // ), + // ), + children: [ + for (var commit in commits) ...[ + LinkWidget( + url: + '/gitee/$owner/$name/commits/${commit.sha}', + child: Container( + padding: const EdgeInsets.symmetric( + vertical: 8), + child: Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Text( + commit.sha!.substring(0, 7), + style: TextStyle( + color: AntTheme.of(context) + .colorPrimary, + fontSize: 17, + fontFamily: CommonStyle.monospace, ), - ], - ), + ), + ], ), - ) - ] - ], - ), + ), + ) + ] + ], ), ], ), diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index a169f0c..4a02a8e 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -9,8 +9,6 @@ import 'package:tuple/tuple.dart'; import 'package:universal_io/io.dart'; import 'package:url_launcher/url_launcher.dart'; -export 'package:flutter/material.dart' - show Card, ExpansionTile, IconButton; // TODO: remove export 'package:flutter_vector_icons/flutter_vector_icons.dart' show Octicons, Ionicons; diff --git a/lib/widgets/files_item.dart b/lib/widgets/files_item.dart index 0ec9b35..7071dc2 100644 --- a/lib/widgets/files_item.dart +++ b/lib/widgets/files_item.dart @@ -26,20 +26,23 @@ class FilesItem extends StatelessWidget { Widget build(BuildContext context) { final theme = Provider.of(context); final codeProvider = Provider.of(context); - return Card( - color: AntTheme.of(context).colorBackground, - margin: const EdgeInsets.all(0), - child: ExpansionTile( - title: Text( - filename!, - style: TextStyle( - color: AntTheme.of(context).colorPrimary, - fontSize: 18, - fontWeight: FontWeight.w600, + return AntCollapse( + activeKey: const [''], + onChange: (_) { + // TODO: set active + }, + panels: [ + AntCollapsePanel( + key: '', + title: Text( + filename!, + style: TextStyle( + color: AntTheme.of(context).colorPrimary, + fontSize: 18, + fontWeight: FontWeight.w600, + ), ), - ), - children: [ - SingleChildScrollView( + child: SingleChildScrollView( scrollDirection: Axis.horizontal, child: HighlightView( patch!, @@ -51,8 +54,8 @@ class FilesItem extends StatelessWidget { textStyle: codeProvider.fontStyle, ), ), - ], - ), + ), + ], ); } } diff --git a/lib/widgets/release_item.dart b/lib/widgets/release_item.dart index 298dc3d..eef5760 100644 --- a/lib/widgets/release_item.dart +++ b/lib/widgets/release_item.dart @@ -1,21 +1,22 @@ import 'package:antd_mobile/antd_mobile.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_gen/gen_l10n/S.dart'; -import 'package:git_touch/utils/utils.dart'; +import 'package:git_touch/scaffolds/list_stateful.dart'; import 'package:git_touch/widgets/avatar.dart'; import 'package:git_touch/widgets/markdown_view.dart'; import 'package:gql_github/releases.data.gql.dart'; import 'package:timeago/timeago.dart' as timeago; -class ReleaseItem extends StatelessWidget { - const ReleaseItem( - {required this.login, - required this.publishedAt, - required this.name, - required this.tagName, - required this.avatarUrl, - required this.description, - this.releaseAssets}); +class ReleaseItem extends StatefulWidget { + const ReleaseItem({ + required this.login, + required this.publishedAt, + required this.name, + required this.tagName, + required this.avatarUrl, + required this.description, + this.releaseAssets, + }); final String? login; final DateTime? publishedAt; final String? name; @@ -24,6 +25,13 @@ class ReleaseItem extends StatelessWidget { final String? description; final GReleasesData_repository_releases_nodes_releaseAssets? releaseAssets; + @override + State createState() => _ReleaseItemState(); +} + +class _ReleaseItemState extends State { + var _isExpanded = false; + @override Widget build(BuildContext context) { return Column( @@ -32,7 +40,7 @@ class ReleaseItem extends StatelessWidget { height: 12, ), Row(children: [ - Avatar(url: avatarUrl, size: AvatarSize.large), + Avatar(url: widget.avatarUrl, size: AvatarSize.large), const SizedBox(width: 10), Expanded( child: Column( @@ -42,7 +50,7 @@ class ReleaseItem extends StatelessWidget { Row( children: [ Text( - tagName!, + widget.tagName!, style: TextStyle( color: AntTheme.of(context).colorPrimary, fontSize: 18, @@ -58,43 +66,36 @@ class ReleaseItem extends StatelessWidget { fontSize: 16, ), child: Text( - '${login!} ${AppLocalizations.of(context)!.released} ${timeago.format(publishedAt!)}'), + '${widget.login!} ${AppLocalizations.of(context)!.released} ${timeago.format(widget.publishedAt!)}'), ), ], ), ), ]), - if (description != null && description!.isNotEmpty) ...[ + if (widget.description != null && widget.description!.isNotEmpty) ...[ MarkdownFlutterView( - description, + widget.description, ), const SizedBox(height: 10), ], - Card( - color: AntTheme.of(context).colorBox, - margin: const EdgeInsets.all(0), - child: ExpansionTile( - title: Text( - 'Assets (${releaseAssets?.nodes?.length ?? 0})', - style: TextStyle( - color: AntTheme.of(context).colorTextSecondary, - fontSize: 18, - fontWeight: FontWeight.w600, - ), - ), - children: [ - AntList( + AntCollapse( + activeKey: _isExpanded ? [''] : [], + onChange: (_) { + setState(() { + _isExpanded = !_isExpanded; + }); + }, + panels: [ + AntCollapsePanel( + key: '', + title: + Text('Assets (${widget.releaseAssets?.nodes?.length ?? 0})'), + child: AntList( children: [ - if (releaseAssets != null) - for (var asset in releaseAssets!.nodes!) + if (widget.releaseAssets != null) + for (var asset in widget.releaseAssets!.nodes!) AntListItem( - extra: IconButton( - onPressed: () { - context.pushUrl(asset.downloadUrl); - }, - icon: const Icon(Ionicons.download_outline), - ), - arrow: null, + arrow: const Icon(Ionicons.download_outline), child: Text( asset.name, style: TextStyle( @@ -103,11 +104,14 @@ class ReleaseItem extends StatelessWidget { fontWeight: FontWeight.w400, ), ), + onClick: () { + context.pushUrl(asset.downloadUrl); + }, ), ], - ) - ], - ), + ), + ), + ], ) ], ); diff --git a/pubspec.yaml b/pubspec.yaml index 59ee852..db6bda7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -101,7 +101,7 @@ flutter: # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class. - uses-material-design: true + # uses-material-design: true # To add assets to your application, add an assets section, like this: # assets: