@override
Widget build(BuildContext context) {
//SafeArea 适配刘海屏等
return Scaffold(
appBar: AppBar(
title: Text(
_appBarTitle[_currentIndex],
style: TextStyle(color: Color(AppColors.APPBAR)),),
),
//body的pager的滑动PageView来协助实现
body: PageView.builder(
itemBuilder: (BuildContext context, int index){
return _pages[index];
},
controller: _pageController,
//控制可以滑动的数目
itemCount: _pages.length,
//与底部导航栏交互
onPageChanged: (index) {
setState(() {
_currentIndex = index;
});
},
),
bottomNavigationBar: BottomNavigationBar(
//更新当前的条目
currentIndex: _currentIndex,
type: BottomNavigationBarType.fixed,
items: _navigationIconView.map((e) => e.item).toList(),
onTap: (index) {
setState(() {
_currentIndex = index;
});
//底部导航栏的滑动
_pageController.animateToPage(
index, duration: Duration(microseconds: 10), curve: Curves.ease);
},
),
drawer: MyDrawer(
headImgPath: ‘assets/images/cover_img.jpg’,
menuIcons: [Icons.send, Icons.home, Icons.error, Icons.settings],
menuTitles: [‘send’, ‘motivation’, ‘about’, ‘settings’],
),
);
}
}
my_drawer.dart自定义的Drawer,有构造函数和初始化的赋值
import ‘package:flutter/material.dart’;
import ‘file:///D:/Code/Flutter/FlutterHello/flutter_app2/flutter_app2/lib/pages/drawer/about_page.dart’;
import ‘file:///D:/Code/Flutter/FlutterHello/flutter_app2/flutter_app2/lib/pages/drawer/publish_tweet_page.dart’;
import ‘file:///D:/Code/Flutter/FlutterHello/flutter_app2/flutter_app2/lib/pages/drawer/tweet_black_house.dart’;
import ‘package:flutterapp2/pages/drawer/settings_page.dart’;
class MyDrawer extends StatelessWidget {
final String headImgPath;
final List menuTitles;
final List menuIcons;
MyDrawer({Key key,
@required this.headImgPath,
@required this.menuTitles,
-
@required this.menuIcons})
- assert(headImgPath != null),
assert(menuTitles != null),
assert(menuIcons != null),
super(key: key);
@override
Widget build(BuildContext context) {
return Drawer(
elevation: 0.0,//去掉Drawer旁边的阴影
child: ListView.separated(
padding: const EdgeInsets.all(0.0),//去掉上面的状态栏
itemCount: menuTitles.length + 1,
itemBuilder: (context, index) {
if(index == 0) {
return Image.asset(headImgPath, fit: BoxFit.cover, );
}
index -= 1;//去掉最上面的背景条目
return ListTile(
leading: Icon(menuIcons[index]),
title: Text(menuTitles[index]),
trailing: Icon(Icons.arrow_forward_ios),//尾巴
//点击事件
onTap: () {
switch (index) {
case 0:
//PublishTweetPage
_navPush(context, PublishTweetPage());
break;
case 1:
//TweetBlackHousePage
_navPush(context, TweetBlackHousePage());
break;
//aboutPage
case 2:
_navPush(context, aboutPage());
break;
//SettingsPage
case 3:
_navPush(context, SettingsPage());
break;
}
},
);
},
separatorBuilder: (context, index) {
//后面的条目才会有分割线
if(index == 0){
return Divider(
height: 0.0,
);
}else{
return Divider(
height: 1.0,
);
}
},
),
);
}
//条目跳转
_navPush(BuildContext context, Widget page) {
//路由跳转
Navigator.push(context, MaterialPageRoute(builder: (context) => page));
}
}
navigation_icon_view.dart底部导航栏的对象,包含title以及icon的路径,使用构造函数来实现
import ‘package:flutter/material.dart’;
/// 自定义底部导航栏的四个View
class NavigationIconView{
//条目
final BottomNavigationBarItem item;
//title
final String title;
//icon path
final String iconPath;
//actived icon path
final String activeIconPath;
//构造函数,使用命名构造函数的形式进行赋值
NavigationIconView({
@required this.title, @required this.iconPath, @required this.activeIconPath})
:item = BottomNavigationBarItem(
icon: Image.asset(iconPath,
width: 20.0,
height: 20.0,),
activeIcon: Image.asset(activeIconPath,
width: 20.0,
height: 20.0,),
title: Text(title)
);
}
about_page.dart左侧滑栏的about条目
import ‘package:flutter/material.dart’;
class aboutPage extends StatefulWidget {
@override
_aboutPageState createState() => _aboutPageState();
}
class _aboutPageState extends State {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(‘about’),
),
);
}
}
publish_tweet_page.dart
import ‘package:flutter/material.dart’;
class PublishTweetPage extends StatefulWidget {
@override
_PublishTweetPageState createState() => _PublishTweetPageState();
}
class _PublishTweetPageState extends State {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(‘send’),
),
);
}
}
settings_page.dart
import ‘package:flutter/material.dart’;
class SettingsPage extends StatefulWidget {
@override
_SettingsPageState createState() => _SettingsPageState();
}
class _SettingsPageState extends State {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(‘settings’),
),
);
}
}
tweet_black_house.dart
import ‘package:flutter/material.dart’;
class TweetBlackHousePage extends StatefulWidget {
@override
_TweetBlackHousePageState createState() => _TweetBlackHousePageState();
}
class _TweetBlackHousePageState extends State {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(‘motivation’),
),
);
}
}
news_list_page.dart主界面的News
import ‘package:flutter/material.dart’;
class NewsListPage extends StatefulWidget {
@override
_NewsListPageState createState() => _NewsListPageState();
}
class _NewsListPageState extends State {
@override
Widg
《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》
【docs.qq.com/doc/DSmxTbFJ1cmN1R2dB】 完整内容开源分享
et build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(‘News’),
),
);
}
}
profile_page.dart主界面的My
import ‘package:flutter/material.dart’;
class ProfilePage extends StatefulWidget {
@override
_ProfilePageState createState() => _ProfilePageState();
}
class _ProfilePageState extends State {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(‘My’),
),
);
}
}
tweet_page.dart主界面的Updates
import ‘package:flutter/material.dart’;



