**Flutter里StatefulWidge组件的含义为 有状态的组件类,StatelessWidget为无状态的组件,这篇只说StatefulWidget
**

先看效果图



首页是一个可以左右滑动的ViewPager,我的里面是一个TextView,EditText

贴一下代码

import 'package:flutter/material.dart';class StatefulLearn extends StatefulWidget {  @override  _StatefulLearnState createState() => _StatefulLearnState();}class _StatefulLearnState extends State {  var _currentIndex=0;   //当前选中下标  @override  Widget build(BuildContext context) {    return MaterialApp(      title: "我的导航栏app",      home: Scaffold(      body: _currentIndex==0?Container(          child: PageView(            children: [              _item("page1",Colors.blue),              _item("page2",Colors.red),              _item("page3",Colors.yellow),            ],          ),        ):RefreshIndicator(  //下拉刷新控件          child: ListView(             children: [               Container(                 child: Text("我的里面的内容"),                 color: Colors.red,               ),               Container(                 child: TextField(                  maxLength: 10,                   maxLines: 1,                   decoration: InputDecoration(                     icon:new Icon( Icons.home),                     hintText: "请输入姓名",                     hintStyle: TextStyle(                       fontSize: 18                     )                   ),                 ),               )             ],          ),          onRefresh:_refreshHandler ,        ),        bottomNavigationBar: BottomNavigationBar(          //样式          items: [          BottomNavigationBarItem(            icon: new Icon(Icons.home,color: Colors.grey),            activeIcon: new Icon(Icons.home,color: Colors.blue),            title: new Text("首页")          ),          BottomNavigationBarItem(              icon: new Icon(Icons.list,color: Colors.grey),              activeIcon: new Icon(Icons.list,color: Colors.blue),              title: new Text("我的")          )        ],          //设置选中下标          currentIndex: _currentIndex,          onTap: (i){            setState(() {              _currentIndex=i;            });          },        ),      ),    );  }//下拉刷新 200ms完成刷新    Future _refreshHandler() async{    await Future.delayed(Duration(milliseconds: 500));  }//PageView的item布局  方法  _item(String t, Color c) {      return Container(        decoration: BoxDecoration(          color: c        ),        child: new Text(          t,style: new TextStyle(          color: Colors.white,          fontSize: 20        ),        ),      );  }}

更多相关文章

  1. Android(安卓)知识点总结 (二) view绘制流程
  2. android RecyclerView局部刷新
  3. Dev Guide_Android(安卓)Basics_Application Fundamentals
  4. Android(安卓)组件化开发ButterKnife配置和相关问题
  5. [置顶] Android实现RecyclerView的下拉刷新和上拉加载更多
  6. Lifecycle-Aware Components生命周期组件 Lifecycle、LiveData
  7. 再也不信网上流传的方法了!!android创建组件的真正写法!
  8. android ListView上拉加载更多 下拉刷新功能实现(采用pull-to-ref
  9. Android(安卓)界面刷新

随机推荐

  1. Android UI控件之ListView实现圆角效果
  2. Android之UI学习篇十二:ListView控件学习(
  3. 如今的移动操作系统,写在2013年——androi
  4. 浅谈Android移动架构(一)创建型模式之工
  5. 自定义RatingBar的显示(评分组件)
  6. 华为面试题:Android 的优势与不足
  7. android错误:The method makeText(Context
  8. 25000字总结Android优秀的第三方框架、各
  9. 《Android实例剖析笔记》系列文章
  10. android Canvas drawText 文字居中