Flutter 工具类 App 开发示例:包含三个 Tab 页面
以下是一个简单的示例代码,实现了一个具有三个 tab 的工具类 app,第一个 tab 有五个子 tab,第二个 tab 是收藏页面,第三个 tab 是设置页面。
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Toolbox',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Toolbox'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin {
TabController _tabController;
@override
void initState() {
super.initState();
_tabController = TabController(length: 5, vsync: this);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
bottom: TabBar(
controller: _tabController,
tabs: [
Tab(text: '热门'),
Tab(text: '音频'),
Tab(text: '视频'),
Tab(text: '图片'),
Tab(text: '文件转换'),
],
),
),
body: TabBarView(
controller: _tabController,
children: [
Center(child: Text('热门')),
Center(child: Text('音频')),
Center(child: Text('视频')),
Center(child: Text('图片')),
Center(child: Text('文件转换')),
],
),
bottomNavigationBar: BottomNavigationBar(
items: [
BottomNavigationBarItem(icon: Icon(Icons.star), label: '收藏'),
BottomNavigationBarItem(icon: Icon(Icons.settings), label: '设置'),
],
),
);
}
@override
void dispose() {
_tabController.dispose();
super.dispose();
}
}
原文地址: https://www.cveoy.top/t/topic/lRQj 著作权归作者所有。请勿转载和采集!