Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import './destination.dart';
- class HomePage extends StatefulWidget {
- @override
- _HomePageState createState() => _HomePageState();
- }
- class _HomePageState extends State<HomePage> with TickerProviderStateMixin<HomePage> {
- List<Key> _destinationKeys;
- List<AnimationController> _faders;
- int _currentIndex = 0;
- @override
- void initState() {
- super.initState();
- _faders = allDestinations.map<AnimationController>((Destination destination) {
- return AnimationController(vsync: this, duration: Duration(milliseconds: 200));
- }).toList();
- _faders[_currentIndex].value = 1.0;
- _destinationKeys = List<Key>.generate(allDestinations.length, (int index) => GlobalKey()).toList();
- }
- @override
- void dispose() {
- for (AnimationController controller in _faders)
- controller.dispose();
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- body: SafeArea(
- top: false,
- child: Stack(
- fit: StackFit.expand,
- children: allDestinations.map((Destination destination) {
- final Widget view = FadeTransition(
- opacity: _faders[destination.index].drive(CurveTween(curve: Curves.fastOutSlowIn)),
- child: KeyedSubtree(
- key: _destinationKeys[destination.index],
- child: DestinationView(
- destination: destination,
- ),
- ),
- );
- if (destination.index == _currentIndex) {
- _faders[destination.index].forward();
- return view;
- } else {
- _faders[destination.index].reverse();
- if (_faders[destination.index].isAnimating) {
- return IgnorePointer(child: view);
- }
- return Offstage(child: view);
- }
- }).toList(),
- ),
- ),
- bottomNavigationBar: BottomNavigationBar(
- currentIndex: _currentIndex,
- onTap: (int index) {
- setState(() {
- _currentIndex = index;
- });
- },
- items: allDestinations.map((Destination destination) {
- return BottomNavigationBarItem(
- icon: Icon(destination.icon),
- backgroundColor: destination.color,
- title: Text(destination.title)
- );
- }).toList(),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement