1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
| import 'package:flutter/material.dart'; import 'package:jxz/widget/my_appbar.dart';
class DemoBottomBarPage extends StatefulWidget { @override _DemoBottomBarPageState createState() => _DemoBottomBarPageState(); }
class _DemoBottomBarPageState extends State<DemoBottomBarPage> { PageController _pageController; List<Widget> _eachView; int _index = 0;
@override void initState() { _eachView = List(); _eachView..add(EachView())..add(EachView2());
this._pageController = PageController(initialPage: this._index, keepPage: true); super.initState(); }
@override void dispose() { _pageController.dispose(); super.dispose(); }
@override Widget build(BuildContext context) { return Scaffold( appBar: MyAppBar(title: '底部导航'), floatingActionButton: FloatingActionButton( onPressed: () { Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) { return EachView(); })); }, tooltip: '新建页', backgroundColor: Colors.indigoAccent, child: Icon( Icons.add, color: Colors.white, )), floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, bottomNavigationBar: BottomAppBar( color: Colors.indigo, shape: CircularNotchedRectangle(), child: Row( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceAround, children: <Widget>[ IconButton( icon: Icon(Icons.home), color: Colors.white, onPressed: () { setState(() { _index = 0; _pageController.jumpToPage(_index); }); }, ), IconButton( icon: Icon(Icons.person), color: Colors.white, onPressed: () { setState(() { _index = 1; _pageController.jumpToPage(_index); }); }, ), ], ), ), body: PageView( physics: NeverScrollableScrollPhysics(), controller: _pageController, children: _eachView, ), ); } }
class EachView extends StatefulWidget { @override _EachViewState createState() => _EachViewState(); }
class _EachViewState extends State<EachView> with AutomaticKeepAliveClientMixin { @override bool get wantKeepAlive => true;
@override Widget build(BuildContext context) { return Center( child: Container( width: 220, child: TextFormField( decoration: InputDecoration(labelText: '手机号', hintText: '请输入手机号'), ))); } }
class EachView2 extends StatefulWidget { @override _EachView2State createState() => _EachView2State(); }
class _EachView2State extends State<EachView2> with AutomaticKeepAliveClientMixin { @override bool get wantKeepAlive => true;
List devices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
@override Widget build(BuildContext context) { return ListView.builder( itemCount: devices.length, itemExtent: 120, itemBuilder: (_, index) => Card(child: Center(child: Text('当前Item:${index}'))), ); } }
|