selfprivacy.org.app/lib/ui/pages/root_route.dart
2022-05-30 16:49:42 +03:00

112 lines
3.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:selfprivacy/logic/api_maps/server.dart';
import 'package:selfprivacy/ui/components/brand_tab_bar/brand_tab_bar.dart';
import 'package:selfprivacy/ui/pages/more/more.dart';
import 'package:selfprivacy/ui/pages/providers/providers.dart';
import 'package:selfprivacy/ui/pages/services/services.dart';
import 'package:selfprivacy/ui/pages/users/users.dart';
import '../components/pre_styled_buttons/flash_fab.dart';
class RootPage extends StatefulWidget {
const RootPage({Key? key}) : super(key: key);
@override
State<RootPage> createState() => _RootPageState();
}
class _RootPageState extends State<RootPage> with TickerProviderStateMixin {
late TabController tabController;
late final AnimationController _controller = AnimationController(
duration: const Duration(milliseconds: 400),
vsync: this,
);
late final Animation<double> _animation = CurvedAnimation(
parent: _controller,
curve: Curves.fastOutSlowIn,
);
@override
void initState() {
tabController = TabController(length: 4, vsync: this);
tabController.addListener(() {
setState(() {
tabController.index == 2
? _controller.forward()
: _controller.reverse();
});
});
super.initState();
}
@override
void dispose() {
tabController.dispose();
_controller.dispose();
super.dispose();
}
var selfprivacyServer = ServerApi();
@override
Widget build(BuildContext context) {
return SafeArea(
child: Provider<ChangeTab>(
create: (_) => ChangeTab(tabController.animateTo),
child: Scaffold(
body: TabBarView(
controller: tabController,
children: const [
ProvidersPage(),
ServicesPage(),
UsersPage(),
MorePage(),
],
),
bottomNavigationBar: BrandTabBar(
controller: tabController,
),
floatingActionButton: SizedBox(
height: 104 + 16,
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end,
children: [
ScaleTransition(
scale: _animation,
child: FloatingActionButton.small(
heroTag: 'new_user_fab',
onPressed: () {
showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (BuildContext context) {
return Padding(
padding: MediaQuery.of(context).viewInsets,
child: NewUser());
},
);
},
child: const Icon(Icons.person_add_outlined),
),
),
const SizedBox(height: 16),
const BrandFab(),
],
),
),
),
),
);
}
}
class ChangeTab {
final ValueChanged<int> onPress;
ChangeTab(this.onPress);
}