为什么Flutter的BottomBarNavigationDemo示例会重置每个视图的状态?

时间:2018-03-04 07:10:34

标签: intellij-idea widget dart flutter bottomnavigationview

以下是我对NavigationIconViewClass的修改

import 'package:flutter/material.dart';
import 'package:myfluttertest/screens/bottom_navigation/profile/home_screen.dart';

class NavigationIconView {
  NavigationIconView({
    Widget icon,
    String title,
    Widget screen,
    Color color,
    TickerProvider vsync,
  }) : _icon = icon,
        _color = color,
        _title = title,
        _screen = screen,
        item = new BottomNavigationBarItem(
          icon: icon,
          title: new Text(title),
          backgroundColor: color,
        ),
        controller = new AnimationController(
          duration: kThemeAnimationDuration,
          vsync: vsync,
        ) {
            _animation = new CurvedAnimation(
              parent: controller,
              curve: const Interval(0.5, 1.0, curve: Curves.fastOutSlowIn),
            );
          }

  final Widget _icon;
  final Color _color;
  final String _title;
  final Widget _screen;
  final BottomNavigationBarItem item;
  final AnimationController controller;
  CurvedAnimation _animation;

  FadeTransition transition(BottomNavigationBarType type, BuildContext context) {
    Color iconColor;
    if (type == BottomNavigationBarType.shifting) {
      iconColor = _color;
    } else {
      final ThemeData themeData = Theme.of(context);
      iconColor = themeData.brightness == Brightness.light
          ? themeData.primaryColor
          : themeData.accentColor;
    }

    return new FadeTransition(
      opacity: _animation,
      child: new SlideTransition(
        position: new Tween<Offset>(
          begin: const Offset(0.0, 0.02), // Slightly down.
          end: Offset.zero,
        ).animate(_animation),

        child: _screen,
/*
        //TODO: PERSONALIZE VIEW IN HERE.
        ////
        child: new IconTheme(
          data: new IconThemeData(
            color: iconColor,
            size: 120.0,
          ),
          child: new Semantics(
            label: 'Placeholder for $_title tab',
            child: _icon,
          ),
        ),
       ///
*/
      ),
    );
  }
}

在这里,我为构造函数添加了一个Widget类型的屏幕,以表示每个Icon视图转换的子视图。我已经使用默认为项目的MyHomeScreen应用程序对其进行了测试。每次我将视图从这一组更改为另一组时,计数器都会重置。稍后在我的应用程序中,我希望保留视图,以便用户不会在选项卡中丢失位置。

0 个答案:

没有答案