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

109 lines
2.9 KiB
Dart
Raw Normal View History

2022-09-17 14:35:45 +02:00
import 'package:flutter/widgets.dart';
2020-01-29 06:45:22 +01:00
import 'package:git_touch/models/theme.dart';
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
import 'package:provider/provider.dart';
class UserHeader extends StatelessWidget {
2021-05-16 09:16:35 +02:00
final String? avatarUrl;
final String? name;
final String? login;
final DateTime? createdAt;
final String? bio;
2022-09-18 07:02:06 +02:00
final bool isViewer;
final List<Widget> rightWidgets;
2020-01-29 06:45:22 +01:00
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 [],
});
2020-01-29 06:45:22 +01:00
@override
Widget build(BuildContext context) {
final theme = Provider.of<ThemeModel>(context);
2022-09-18 07:02:06 +02:00
final right = isViewer
? [
MutationButton(
text: 'Switch accounts',
onTap: () {
theme.push(context, '/login');
},
)
]
: 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-09-06 18:28:12 +02:00
const SizedBox(height: 8),
2021-05-16 09:16:35 +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(
color: theme.palette.text,
fontSize: 20,
fontWeight: FontWeight.w600,
),
),
2022-09-06 18:28:12 +02:00
const SizedBox(height: 4),
2020-01-29 06:45:22 +01:00
],
Text(
2021-05-16 09:16:35 +02:00
login!,
2020-01-29 06:45:22 +01:00
style: TextStyle(
color: theme.palette.primary,
fontSize: 18,
),
),
2022-09-06 18:28:12 +02:00
const SizedBox(height: 8),
2020-01-31 15:45:40 +01:00
if (createdAt != null)
Row(
children: <Widget>[
Icon(
Octicons.clock,
size: 16,
2020-01-29 06:45:22 +01:00
color: theme.palette.tertiaryText,
),
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(
color: theme.palette.tertiaryText,
fontSize: 16,
),
),
],
),
2021-05-16 09:16:35 +02:00
if (bio != null && bio!.isNotEmpty) ...[
2022-09-06 18:28:12 +02:00
const SizedBox(height: 10),
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(
color: theme.palette.secondaryText,
fontSize: 17,
),
)
]
],
),
);
}
}