git-touch-android-ios-app/lib/widgets/user_header.dart

97 lines
2.7 KiB
Dart
Raw Normal View History

2022-09-24 20:46:37 +02:00
import 'package:antd_mobile/antd_mobile.dart';
2022-09-17 14:35:45 +02:00
import 'package:flutter/widgets.dart';
2022-10-07 18:55:47 +02:00
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
2020-01-29 06:45:22 +01:00
import 'package:git_touch/utils/utils.dart';
import 'package:git_touch/widgets/avatar.dart';
import 'package:git_touch/widgets/mutation_button.dart';
2020-01-29 06:45:22 +01:00
class UserHeader extends StatelessWidget {
2022-09-18 07:02:06 +02:00
const UserHeader({
super.key,
2021-05-16 09:16:35 +02:00
required this.avatarUrl,
required this.name,
required this.login,
required this.createdAt,
required this.bio,
2022-09-18 07:02:06 +02:00
this.isViewer = false,
this.rightWidgets = const [],
});
2022-09-21 18:28:21 +02:00
final String? avatarUrl;
final String? name;
final String? login;
final DateTime? createdAt;
final String? bio;
final bool isViewer;
final List<Widget> rightWidgets;
2020-01-29 06:45:22 +01:00
@override
Widget build(BuildContext context) {
2022-09-18 07:02:06 +02:00
final right = isViewer
? [
MutationButton(
text: 'Switch accounts',
onTap: () {
2022-09-22 19:50:45 +02:00
context.pushUrl('/login');
2022-09-18 07:02:06 +02:00
},
)
]
: rightWidgets;
2020-01-29 06:45:22 +01:00
return Container(
padding: CommonStyle.padding,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Row(
children: <Widget>[
Avatar(url: avatarUrl, size: AvatarSize.extraLarge),
2022-09-18 07:02:06 +02:00
if (right.isNotEmpty) ...[
2020-01-29 06:45:22 +01:00
Expanded(child: Container()),
2022-09-18 07:02:06 +02:00
...right,
2020-01-29 06:45:22 +01:00
]
],
),
2022-10-08 20:52:20 +02:00
if (name != null && name!.isNotEmpty)
2020-01-29 06:45:22 +01:00
Text(
2021-05-16 09:16:35 +02:00
name!,
2020-01-29 06:45:22 +01:00
style: TextStyle(
2022-09-24 20:46:37 +02:00
color: AntTheme.of(context).colorText,
2020-01-29 06:45:22 +01:00
fontSize: 20,
fontWeight: FontWeight.w600,
),
),
Text(
2021-05-16 09:16:35 +02:00
login!,
2020-01-29 06:45:22 +01:00
style: TextStyle(
2022-10-08 20:52:20 +02:00
color: AntTheme.of(context).colorPrimary, fontSize: 18),
2020-01-29 06:45:22 +01:00
),
2020-01-31 15:45:40 +01:00
if (createdAt != null)
Row(
children: <Widget>[
Icon(
Octicons.clock,
size: 16,
2022-09-24 20:46:37 +02:00
color: AntTheme.of(context).colorWeak,
2020-01-29 06:45:22 +01:00
),
2022-09-06 18:28:12 +02:00
const SizedBox(width: 4),
2020-01-31 15:45:40 +01:00
Text(
2021-05-16 09:16:35 +02:00
'Joined on ${dateFormat.format(createdAt!)}',
2020-01-31 15:45:40 +01:00
style: TextStyle(
2022-10-08 20:52:20 +02:00
color: AntTheme.of(context).colorWeak, fontSize: 16),
2020-01-31 15:45:40 +01:00
),
],
),
2022-10-08 20:52:20 +02:00
if (bio != null && bio!.isNotEmpty)
2020-01-29 06:45:22 +01:00
Text(
2021-05-16 09:16:35 +02:00
bio!,
2020-01-29 06:45:22 +01:00
style: TextStyle(
2022-09-24 20:46:37 +02:00
color: AntTheme.of(context).colorTextSecondary,
2020-01-29 06:45:22 +01:00
fontSize: 17,
),
)
2022-10-08 20:52:20 +02:00
].withSeparator(const SizedBox(height: 8)),
2020-01-29 06:45:22 +01:00
),
);
}
}