iOS风格的页面布局脚手架结构,可指定最底部的导航切换栏可主体内容页。
相关组件
CupertinoTabScaffold基本用法
【tabBar】 : 页签条 【CupertinoTabBar】
【backgroundColor】 : 背景色 【Color】
【controller】 : 控制器 【CupertinoTabController】
【tabBuilder】 : 页面构造器 【IndexedWidgetBuilder】
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class CustomCupertinoTabScaffold extends StatefulWidget {
@override
_CustomCupertinoTabScaffoldState createState() =>
_CustomCupertinoTabScaffoldState();
}
class _CustomCupertinoTabScaffoldState
extends State<CustomCupertinoTabScaffold> {
var _position = 0;
final iconsMap = {
//底栏图标
"图鉴": Icons.home, "动态": Icons.toys,
"喜欢": Icons.favorite, "手册": Icons.class_,
"我的": Icons.account_circle,
};
@override
Widget build(BuildContext context) {
return Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height - 300,
child: CupertinoTabScaffold(
backgroundColor: Colors.grey.withAlpha(11),
tabBar: _buildTabBar(),
tabBuilder: (_, index) => _buildContent(index)),
);
}
CupertinoTabBar _buildTabBar() => CupertinoTabBar(
currentIndex: _position,
onTap: (value) => setState(() => _position = value),
items: iconsMap.keys
.map((e) => BottomNavigationBarItem(
icon: Icon(
iconsMap[e],
),
title: Text(e),
))
.toList(),
activeColor: Colors.blue,
inactiveColor: Color(0xff333333),
backgroundColor: Color(0xfff1f1f1),
iconSize: 25.0,
);
_buildContent(int index) => Container(
alignment: Alignment.center,
child: Text(iconsMap.keys.toList()[index]),
);
}