From fac17a69efedfb0b0886ea55e901d42849ab8f82 Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Sun, 18 Sep 2022 13:02:06 +0800 Subject: [PATCH] refactor: mutation button --- lib/widgets/mutation_button.dart | 44 +++++++++----------------------- lib/widgets/user_header.dart | 34 +++++++++++++----------- pubspec.lock | 8 +++--- pubspec.yaml | 1 - 4 files changed, 35 insertions(+), 52 deletions(-) diff --git a/lib/widgets/mutation_button.dart b/lib/widgets/mutation_button.dart index 9f50249..07569b4 100644 --- a/lib/widgets/mutation_button.dart +++ b/lib/widgets/mutation_button.dart @@ -1,46 +1,26 @@ +import 'package:antd_mobile/antd_mobile.dart'; import 'package:flutter/cupertino.dart'; -import 'package:git_touch/models/theme.dart'; -import 'package:git_touch/widgets/link.dart'; -import 'package:provider/provider.dart'; class MutationButton extends StatelessWidget { - final bool? active; + final bool active; final String text; - final String? url; - final VoidCallback? onTap; + final VoidCallback onTap; const MutationButton({ - required this.active, + super.key, + this.active = false, required this.text, - this.url, - this.onTap, + required this.onTap, }); @override Widget build(BuildContext context) { - final theme = Provider.of(context); - final textColor = - active! ? theme.palette.background : theme.palette.primary; - final backgroundColor = - active! ? theme.palette.primary : theme.palette.background; - return LinkWidget( - url: url, - onTap: onTap, - child: Container( - padding: const EdgeInsets.symmetric( - horizontal: 12, - vertical: 4, - ), - decoration: BoxDecoration( - color: backgroundColor, - borderRadius: const BorderRadius.all(Radius.circular(20)), - border: Border.all(color: theme.palette.primary), - ), - child: Text( - text, - style: TextStyle(fontSize: 17, color: textColor), - ), - ), + return AntButton( + color: AntTheme.primary, + fill: active ? AntButtonFill.solid : AntButtonFill.outline, + shape: AntButtonShape.rounded, + onClick: onTap, + child: Text(text), ); } } diff --git a/lib/widgets/user_header.dart b/lib/widgets/user_header.dart index 15dd2e6..9a42f13 100644 --- a/lib/widgets/user_header.dart +++ b/lib/widgets/user_header.dart @@ -11,30 +11,34 @@ class UserHeader extends StatelessWidget { final String? login; final DateTime? createdAt; final String? bio; + final bool isViewer; final List rightWidgets; - UserHeader({ + const UserHeader({ + super.key, required this.avatarUrl, required this.name, required this.login, required this.createdAt, required this.bio, - bool isViewer = false, - List? rightWidgets, - }) : rightWidgets = [ - if (isViewer) - const MutationButton( - active: false, - text: 'Switch accounts', - url: '/login', - ) - else - ...(rightWidgets ?? []), - ]; + this.isViewer = false, + this.rightWidgets = const [], + }); @override Widget build(BuildContext context) { final theme = Provider.of(context); + final right = isViewer + ? [ + MutationButton( + text: 'Switch accounts', + onTap: () { + theme.push(context, '/login'); + }, + ) + ] + : rightWidgets; + return Container( padding: CommonStyle.padding, child: Column( @@ -43,9 +47,9 @@ class UserHeader extends StatelessWidget { Row( children: [ Avatar(url: avatarUrl, size: AvatarSize.extraLarge), - if (rightWidgets.isNotEmpty) ...[ + if (right.isNotEmpty) ...[ Expanded(child: Container()), - ...rightWidgets, + ...right, ] ], ), diff --git a/pubspec.lock b/pubspec.lock index 24e665a..a732b4b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -313,10 +313,10 @@ packages: flutter_vector_icons: dependency: "direct main" description: - path: "../flutter-vector-icons" - relative: true - source: path - version: "1.0.0" + name: flutter_vector_icons + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" flutter_web_plugins: dependency: transitive description: flutter diff --git a/pubspec.yaml b/pubspec.yaml index 04d2bbe..830f5a7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -41,7 +41,6 @@ dependencies: flutter_markdown: flutter_svg: flutter_vector_icons: - path: ../flutter-vector-icons github: github_trending: gql: