import 'package:flutter/material.dart';
class StatefulWidgetPage extends StatefulWidget {
@override
_StatefulWidgetPageState createState() => _StatefulWidgetPageState();
}
class _StatefulWidgetPageState extends State<StatefulWidgetPage> {
int _currentSelectedIndex = 0;
@override
Widget build(BuildContext context) {
TextStyle textStyle = TextStyle(fontSize: 20, color: Colors.red);
return MaterialApp(
title: 'StatefulWidgetPage 组件示例',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(title: Text('StatefulWidgetPage 组件示例'),),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentSelectedIndex,
onTap: (index){
setState(() {
_currentSelectedIndex = index;
});
},
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home, color: Colors.grey,),
activeIcon: Icon(Icons.home, color: Colors.red,),
title: Text("主页")
),
BottomNavigationBarItem(
icon: Icon(Icons.settings, color: Colors.grey,),
activeIcon: Icon(Icons.settings, color: Colors.red,),
title: Text("设置")
)
],),
floatingActionButton: FloatingActionButton(
onPressed: (){
print("悬浮按钮点击");
},
child: Text("悬浮按钮组件"),
),
body:
_currentSelectedIndex == 0 ?
RefreshIndicator(
child: ListView(
children: <Widget>[
Container(
decoration: BoxDecoration(color: Colors.white),
alignment: Alignment.center,
child: Column(
children: <Widget>[
Text("主页面选项卡, 下拉刷新")
],
),
),
],
),
onRefresh: _refreshIndicatorOnRefresh,
)
:
Container(
decoration: BoxDecoration(color: Colors.white),
alignment: Alignment.center,
child: Column(
children: <Widget>[
Text("设置页面选项卡")
],
),
) ,
),
);
}
Future<Null> _refreshIndicatorOnRefresh() async{
await Future.delayed(Duration(milliseconds: 500));
return null;
}
}