refactor: mutation button

This commit is contained in:
Rongjian Zhang 2022-09-18 13:02:06 +08:00
parent d9c50cd0a9
commit fac17a69ef
4 changed files with 35 additions and 52 deletions

View File

@ -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<ThemeModel>(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),
);
}
}

View File

@ -11,30 +11,34 @@ class UserHeader extends StatelessWidget {
final String? login;
final DateTime? createdAt;
final String? bio;
final bool isViewer;
final List<Widget> 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<Widget>? 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<ThemeModel>(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: <Widget>[
Avatar(url: avatarUrl, size: AvatarSize.extraLarge),
if (rightWidgets.isNotEmpty) ...[
if (right.isNotEmpty) ...[
Expanded(child: Container()),
...rightWidgets,
...right,
]
],
),

View File

@ -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

View File

@ -41,7 +41,6 @@ dependencies:
flutter_markdown:
flutter_svg:
flutter_vector_icons:
path: ../flutter-vector-icons
github:
github_trending:
gql: