selfprivacy.org.app/lib/ui/pages/root_route.dart

98 lines
2.8 KiB
Dart
Raw Normal View History

2020-11-29 22:07:46 +02:00
import 'package:flutter/material.dart';
2022-05-31 02:06:08 +03:00
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
2020-11-29 22:07:46 +02:00
import 'package:selfprivacy/ui/components/brand_tab_bar/brand_tab_bar.dart';
2020-12-02 11:16:23 +02:00
import 'package:selfprivacy/ui/pages/more/more.dart';
2020-12-03 18:52:53 +02:00
import 'package:selfprivacy/ui/pages/providers/providers.dart';
2020-12-01 21:08:19 +02:00
import 'package:selfprivacy/ui/pages/services/services.dart';
2020-12-03 18:52:53 +02:00
import 'package:selfprivacy/ui/pages/users/users.dart';
2020-11-29 22:07:46 +02:00
2022-06-05 22:36:32 +03:00
import 'package:selfprivacy/ui/components/pre_styled_buttons/flash_fab.dart';
2022-05-17 01:41:00 +03:00
2020-11-29 22:07:46 +02:00
class RootPage extends StatefulWidget {
const RootPage({super.key});
2020-11-29 22:07:46 +02:00
@override
State<RootPage> createState() => _RootPageState();
2020-11-29 22:07:46 +02:00
}
2022-05-30 16:49:42 +03:00
class _RootPageState extends State<RootPage> with TickerProviderStateMixin {
2021-03-18 02:55:38 +02:00
late TabController tabController;
2020-11-29 22:07:46 +02:00
2022-05-30 16:49:42 +03:00
late final AnimationController _controller = AnimationController(
duration: const Duration(milliseconds: 400),
vsync: this,
);
late final Animation<double> _animation = CurvedAnimation(
parent: _controller,
curve: Curves.fastOutSlowIn,
);
2020-11-29 22:07:46 +02:00
@override
void initState() {
tabController = TabController(length: 4, vsync: this);
2022-05-30 16:49:42 +03:00
tabController.addListener(() {
setState(() {
tabController.index == 2
? _controller.forward()
: _controller.reverse();
});
});
2020-11-29 22:07:46 +02:00
super.initState();
}
@override
void dispose() {
2021-03-18 02:55:38 +02:00
tabController.dispose();
2022-05-30 16:49:42 +03:00
_controller.dispose();
super.dispose();
2020-11-29 22:07:46 +02:00
}
@override
2022-06-05 22:36:32 +03:00
Widget build(final BuildContext context) {
final bool isReady = context.watch<ServerInstallationCubit>().state
2022-05-31 02:06:08 +03:00
is ServerInstallationFinished;
2020-11-29 22:07:46 +02:00
return SafeArea(
2022-05-30 16:49:42 +03:00
child: Provider<ChangeTab>(
2022-06-05 22:36:32 +03:00
create: (final _) => ChangeTab(tabController.animateTo),
2022-05-30 16:49:42 +03:00
child: Scaffold(
body: TabBarView(
2021-03-18 02:55:38 +02:00
controller: tabController,
2022-05-24 21:55:39 +03:00
children: const [
2021-03-18 02:55:38 +02:00
ProvidersPage(),
ServicesPage(),
UsersPage(),
MorePage(),
],
),
2022-05-30 16:49:42 +03:00
bottomNavigationBar: BrandTabBar(
controller: tabController,
),
2022-05-31 02:06:08 +03:00
floatingActionButton: isReady
? SizedBox(
height: 104 + 16,
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end,
children: [
ScaleTransition(
scale: _animation,
child: const AddUserFab(),
),
const SizedBox(height: 16),
const BrandFab(),
],
2022-05-30 16:49:42 +03:00
),
2022-05-31 02:06:08 +03:00
)
: null,
2020-11-29 22:07:46 +02:00
),
),
);
}
}
2021-03-18 02:55:38 +02:00
class ChangeTab {
ChangeTab(this.onPress);
2022-06-05 22:36:32 +03:00
final ValueChanged<int> onPress;
2021-03-18 02:55:38 +02:00
}