flutter如何实现切换页面缓存

本文小编为入门教程大家详细介绍“flutter如何实现切换页面缓存”,内容详细,flutter 页面切换,步骤清晰,细节处理妥当弹窗远程,希望这篇“flutter如何实现切换页面缓存”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。

一、实现底部导航栏动态切换简书页面缓存

实现底部导航栏切换页面缓存需要页面在pubspc.调用yamal中导入proste_indexed_stack插件,这个布局插件可以切换实现懒实例加载,比起实例使用c页面IndexedStack包裹body实现效果图标调用,flutter 如何获取组件的大小,性能快速更好。

dependencies:

#懒加载的层叠组件
proste_indexed_stack:  //不加版本号可获取最新版本

实现底部大小导航切换页面教程缓存只需将bodyProsteIndexedStack包裹一层既可以预览,注意超长获取ProsteIndexedStackchildrenIndexedStackChild类型的,flutter开发技巧,所以系统分析中的超长每一个children 的打印打印每一项都点击需要变颜色用IndexedStackChild包裹

示例:

import 'package:flutter/material.dart';
... //其他需要布局import的内容省略

class RootPage extends StatefulWidget {
  @override
  _RootPageState createState() => _RootPageState();
}

class _RootPageState extends State<RootPage> {
  //底部导航栏数组
  final items = [
    BottomNavigationBarItem(
        icon: Icon(Icons.home),label: '首页',tooltip: ''
    ),
    BottomNavigationBarItem(
        icon: Icon(Icons.music_note),label: '音乐',tooltip: ''
    ),
    BottomNavigationBarItem(
        icon: Icon(Icons.slow_motion_video),label: '短视频',tooltip: ''
    ),
    BottomNavigationBarItem(
        icon: Icon(Icons.account_circle_outlined),label: '我的',tooltip: ''
    ),
  ];

  //底部导航栏页面
  final bodyList = [
    IndexedStackChild(child: HomePage()),
    IndexedStackChild(child: MusicPage()),
    IndexedStackChild(child: TinyVideoPage()),
    IndexedStackChild(child: ProfilePage()),
  ];

  //当前选中页面索引
  int _currentIndex = 0;

  //底部导航栏切换
  void _onTap(int index) {
    setState(() {
      _currentIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: BottomNavigationBar(
        items: items,
        currentIndex: _currentIndex,  //当前选中标识符
        onTap: _onTap,
        type: BottomNavigationBarType.fixed,
      ),
      //ProsteIndexedStack包裹实例,实现变颜色底部导航切换时保持原页面状态
      body: ProsteIndexedStack(
        index: _currentIndex,
        children: bodyList,
      ),
    );
  }
}

二、实现顶部tab切换页面页面缓存点击

顶部tab切换页面缓存操作可使用底部AutomaticKeepAliveClientMixin实现,flutter如何实现切换页面缓存,flutter 调用系统分析分享,只需预览开发在大小页面的state中混入AutomaticKeepAliveClientMixin,然后重写wantKeepAlivetrue即可。

做了以上开发配置,flutter怎么实现按压图标,你如果在打印build print 一下打印技巧,当你切换获取 tabbar 时,print 就不会动态打印入门,也就c实现权限了页面权限保持状态,flutter开发远程打印,flutter超长列表优化。

示例:

import 'package:flutter/material.组件dart';

class ExamplePage extends StatefulWidget {
  @快速override
  _ExamplePageState createState() => _RecommendPageState();
}

class _ExmaplePageState extends State<ExamplePage>
    with AutomaticKeepAliveClientMixin {
  int count = 0;

  void add() {
    setState(() {
      count++;
    });
  }

  @override
  bool get wantKeepAlive => true;

  @override
  void initState() {
    super.initState();
    print('recommend initState');
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
        body:Center(
          child: Text('Example: $count', style: TextStyle(fontSize: 30))
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: add,
          child: Icon(Icons.add),
        ));
  }
}

读到这里,这篇“flutter如何实现切换页面缓存”文章已经介绍完毕,简书 flutter,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会预览,如果想了解超长更多相关变颜色内容的文章,欢迎关注蜗牛博客行业资讯频道。

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,flutter 持续定位,文章观点不代表图标本网站立场,如果涉及优化侵权请联系站长入门邮箱:niceseo99@gmail.com进行举报,flutter能如何预览布局,并提供相关flutter证据分享,一经查实,将立刻点击删除涉嫌侵权内容。

评论

有免费节点资源,我们会通知你!加入纸飞机订阅群

×
天气预报查看日历分享网页手机扫码留言评论电报频道链接