相关疑难解决方法(0)

当使用BottomNavigationBar导航时,如何在颤动中保留窗口小部件状态?

我正在开发一个Flutter应用程序,当使用BottomNavigationBar时,它会在从一个屏幕导航到另一个屏幕时保留状态,然后再返回.就像它适用于Spotify移动应用程序一样; 如果您在其中一个主屏幕上导航层次结构中导航到某个级别,通过底部导航栏更改屏幕,然后更改回旧屏幕,将保留用户在该层次结构中的位置,包括保留国家.

我把头靠在墙上,尝试了各种不同的事情而没有成功.

我想知道如何阻止页面pageChooser(),当用户点击BottomNavigationBar项目时切换,重建自己,而是保留他们已经找到自己的状态(页面都是有状态的小部件).

import 'package:flutter/material.dart';
import './page_plan.dart';
import './page_profile.dart';
import './page_startup_namer.dart';

void main() => runApp(new Recipher());

class Recipher extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Pages();
  }
}

class Pages extends StatefulWidget {
  @override
  createState() => new PagesState();
}

class PagesState extends State<Pages> {
  int pageIndex = 0;


  pageChooser() {
    switch (this.pageIndex) {
      case 0:
        return new ProfilePage();
        break;

      case 1:
        return new PlanPage();
        break;

      case 2:
        return new StartUpNamerPage(); …
Run Code Online (Sandbox Code Playgroud)

dart flutter

22
推荐指数
6
解决办法
1万
查看次数

Flutter:BottomNavigationBar在选项卡更改时重建页面

我在Flutter中的BottomNavigationBar有问题。如果要更改标签,我想让页面保持活动状态。

这是我的实现

底部导航

class Home extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _HomeState();
  }
}

class _HomeState extends State<Home> {
  int _currentIndex = 0;
  List<Widget> _children;
  final Key keyOne = PageStorageKey("IndexTabWidget");

  @override
  void initState() {
    _children = [
      IndexTabWidget(key: keyOne),
      PlaceholderWidget(Colors.green),
      NewsListWidget(),
      ShopsTabWidget(),
      PlaceholderWidget(Colors.blue),
    ];
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(MyApp.appName),
        textTheme: Theme.of(context).textTheme.apply(
              bodyColor: Colors.black,
              displayColor: Colors.blue,
            ),
      ),
      body: _children[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        onTap: onTabTapped,
        key: IHGApp.globalKey,
        fixedColor: Colors.green,
        type: BottomNavigationBarType.fixed,
        currentIndex: …
Run Code Online (Sandbox Code Playgroud)

flutter flutter-layout

19
推荐指数
3
解决办法
7468
查看次数

推到新屏幕时,使底部导航栏保持静态

我是一个飞镖和飞镖的初学者。我一直在尝试navigationBar在我的应用程序的三个不同页面上实现。对于单个页面,切换效果很好,但是我在将所有页面上的活动和非活动标签状态保持不变时遇到问题。似乎当它导航到另一个页面时,我也失去了选项卡的活动状态。这是我的代码。

AppFooter.dart

import 'package:flutter/material.dart';

class AppFooter extends StatefulWidget {
  @override
  _AppFooterState createState() => _AppFooterState();
}

class _AppFooterState extends State<AppFooter> {
  int index = 0;
  @override
  Widget build(BuildContext context) {
    return new Theme(
      data: Theme.of(context).copyWith(
          // sets the background color of the `BottomNavigationBar`
          canvasColor: Colors.white,
          // sets the active color of the `BottomNavigationBar` if `Brightness` is light
          primaryColor: Colors.green,
          textTheme: Theme.of(context)
              .textTheme
              .copyWith(caption: new TextStyle(color: Colors.grey))),
      child: new BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          currentIndex: index,
          onTap: (int index) {
            setState(() { …
Run Code Online (Sandbox Code Playgroud)

dart flutter

5
推荐指数
5
解决办法
5595
查看次数

标签 统计

flutter ×3

dart ×2

flutter-layout ×1