1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-10-23 15:03:22 +00:00
comunicmobile/lib/ui/widgets/mobile_mode/user_page_mobile.dart

97 lines
2.3 KiB
Dart
Raw Normal View History

2020-05-16 08:20:27 +00:00
import 'package:comunic/models/advanced_user_info.dart';
2021-03-17 16:04:45 +00:00
import 'package:comunic/ui/screens/user_page_sections/user_page_header.dart';
import 'package:comunic/ui/screens/user_page_sections/user_posts_section.dart';
2020-05-16 08:20:27 +00:00
import 'package:comunic/utils/intl_utils.dart';
import 'package:flutter/material.dart';
/// Mobile mode of user page
///
/// @author Pierre Hubert
class UserMobilePage extends StatefulWidget {
final AdvancedUserInfo userInfo;
final void Function() onNeedRefresh;
const UserMobilePage({
Key key,
@required this.userInfo,
@required this.onNeedRefresh,
}) : assert(userInfo != null),
assert(onNeedRefresh != null),
super(key: key);
@override
_UserMobilePageState createState() => _UserMobilePageState();
}
2021-03-17 16:04:45 +00:00
class _UserMobilePageState extends State<UserMobilePage>
with SingleTickerProviderStateMixin {
TabController _tabController;
List<UserPageTab> get _tabs => [
// User posts
UserPageTab(
label: tr("Posts"),
onBuild: (c) => UserPostsSection(
user: widget.userInfo,
),
),
];
@override
void initState() {
super.initState();
2020-05-16 08:20:27 +00:00
2021-03-17 16:04:45 +00:00
_tabController = TabController(length: _tabs.length, vsync: this);
}
2020-05-16 08:20:27 +00:00
2021-03-17 16:04:45 +00:00
@override
void dispose() {
_tabController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => Column(children: [
_buildHeader(),
_buildBody(),
]);
Widget _buildHeader() => Material(
color: Colors.blue.shade700,
textStyle: TextStyle(color: Colors.white),
child: Column(
children: [
UserPageHeader(
user: widget.userInfo,
bgColor: Colors.transparent,
2020-05-16 08:20:27 +00:00
),
2021-03-17 16:04:45 +00:00
TabBar(
controller: _tabController,
tabs: _tabs.map((e) => e.tab).toList(),
2020-05-16 08:20:27 +00:00
),
],
),
2021-03-17 16:04:45 +00:00
);
2020-05-16 08:20:27 +00:00
2021-03-17 16:04:45 +00:00
Widget _buildBody() => Expanded(
child: TabBarView(
controller: _tabController,
children: _tabs.map((e) => e.onBuild(context)).toList(),
),
);
}
2020-05-16 08:20:27 +00:00
2021-03-17 16:04:45 +00:00
class UserPageTab {
final String label;
final WidgetBuilder onBuild;
2020-05-16 08:20:27 +00:00
2021-03-17 16:04:45 +00:00
UserPageTab({
@required this.label,
@required this.onBuild,
}) : assert(label != null),
assert(onBuild != null);
Tab get tab => Tab(text: label);
2020-05-16 08:20:27 +00:00
}