refactor: mutation button
This commit is contained in:
parent
d9c50cd0a9
commit
fac17a69ef
|
@ -1,46 +1,26 @@
|
||||||
|
import 'package:antd_mobile/antd_mobile.dart';
|
||||||
import 'package:flutter/cupertino.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 {
|
class MutationButton extends StatelessWidget {
|
||||||
final bool? active;
|
final bool active;
|
||||||
final String text;
|
final String text;
|
||||||
final String? url;
|
final VoidCallback onTap;
|
||||||
final VoidCallback? onTap;
|
|
||||||
|
|
||||||
const MutationButton({
|
const MutationButton({
|
||||||
required this.active,
|
super.key,
|
||||||
|
this.active = false,
|
||||||
required this.text,
|
required this.text,
|
||||||
this.url,
|
required this.onTap,
|
||||||
this.onTap,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Provider.of<ThemeModel>(context);
|
return AntButton(
|
||||||
final textColor =
|
color: AntTheme.primary,
|
||||||
active! ? theme.palette.background : theme.palette.primary;
|
fill: active ? AntButtonFill.solid : AntButtonFill.outline,
|
||||||
final backgroundColor =
|
shape: AntButtonShape.rounded,
|
||||||
active! ? theme.palette.primary : theme.palette.background;
|
onClick: onTap,
|
||||||
return LinkWidget(
|
child: Text(text),
|
||||||
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),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,30 +11,34 @@ class UserHeader extends StatelessWidget {
|
||||||
final String? login;
|
final String? login;
|
||||||
final DateTime? createdAt;
|
final DateTime? createdAt;
|
||||||
final String? bio;
|
final String? bio;
|
||||||
|
final bool isViewer;
|
||||||
final List<Widget> rightWidgets;
|
final List<Widget> rightWidgets;
|
||||||
|
|
||||||
UserHeader({
|
const UserHeader({
|
||||||
|
super.key,
|
||||||
required this.avatarUrl,
|
required this.avatarUrl,
|
||||||
required this.name,
|
required this.name,
|
||||||
required this.login,
|
required this.login,
|
||||||
required this.createdAt,
|
required this.createdAt,
|
||||||
required this.bio,
|
required this.bio,
|
||||||
bool isViewer = false,
|
this.isViewer = false,
|
||||||
List<Widget>? rightWidgets,
|
this.rightWidgets = const [],
|
||||||
}) : rightWidgets = [
|
});
|
||||||
if (isViewer)
|
|
||||||
const MutationButton(
|
|
||||||
active: false,
|
|
||||||
text: 'Switch accounts',
|
|
||||||
url: '/login',
|
|
||||||
)
|
|
||||||
else
|
|
||||||
...(rightWidgets ?? []),
|
|
||||||
];
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Provider.of<ThemeModel>(context);
|
final theme = Provider.of<ThemeModel>(context);
|
||||||
|
final right = isViewer
|
||||||
|
? [
|
||||||
|
MutationButton(
|
||||||
|
text: 'Switch accounts',
|
||||||
|
onTap: () {
|
||||||
|
theme.push(context, '/login');
|
||||||
|
},
|
||||||
|
)
|
||||||
|
]
|
||||||
|
: rightWidgets;
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
padding: CommonStyle.padding,
|
padding: CommonStyle.padding,
|
||||||
child: Column(
|
child: Column(
|
||||||
|
@ -43,9 +47,9 @@ class UserHeader extends StatelessWidget {
|
||||||
Row(
|
Row(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Avatar(url: avatarUrl, size: AvatarSize.extraLarge),
|
Avatar(url: avatarUrl, size: AvatarSize.extraLarge),
|
||||||
if (rightWidgets.isNotEmpty) ...[
|
if (right.isNotEmpty) ...[
|
||||||
Expanded(child: Container()),
|
Expanded(child: Container()),
|
||||||
...rightWidgets,
|
...right,
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
@ -313,10 +313,10 @@ packages:
|
||||||
flutter_vector_icons:
|
flutter_vector_icons:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: "../flutter-vector-icons"
|
name: flutter_vector_icons
|
||||||
relative: true
|
url: "https://pub.dartlang.org"
|
||||||
source: path
|
source: hosted
|
||||||
version: "1.0.0"
|
version: "2.0.0"
|
||||||
flutter_web_plugins:
|
flutter_web_plugins:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description: flutter
|
description: flutter
|
||||||
|
|
|
@ -41,7 +41,6 @@ dependencies:
|
||||||
flutter_markdown:
|
flutter_markdown:
|
||||||
flutter_svg:
|
flutter_svg:
|
||||||
flutter_vector_icons:
|
flutter_vector_icons:
|
||||||
path: ../flutter-vector-icons
|
|
||||||
github:
|
github:
|
||||||
github_trending:
|
github_trending:
|
||||||
gql:
|
gql:
|
||||||
|
|
Loading…
Reference in New Issue