123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import 'package:flutter/material.dart';
- import 'home.dart';
- import 'mine.dart';
- void main() {
- WidgetsFlutterBinding.ensureInitialized();
- runApp(BottomNavigationWidget());
- }
- class BottomNavigationWidget extends StatefulWidget {
- @override
- _BottomNavigationWidgetState createState() => _BottomNavigationWidgetState();
- }
- class _BottomNavigationWidgetState extends State<BottomNavigationWidget> {
- final bottomNavigationColor = Colors.blue;
- int curIndex = 0;
- List<Widget> pages = [];
- @override
- void initState() {
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- pages
- ..add(Home(context))
- ..add(Mine());
- return MaterialApp(
- home: Scaffold(
- body: pages[curIndex],
- bottomNavigationBar: BottomNavigationBar(
- items: [
- BottomNavigationBarItem(
- icon: Icon(Icons.home, color: bottomNavigationColor),
- label: '首页',
- // title: Text('home1', style: TextStyle(color: bottomNavigationColor))
- ),
- BottomNavigationBarItem(
- icon: Icon(Icons.person, color: bottomNavigationColor),
- label: '我的',
- // title: Text('home', style: TextStyle(color: bottomNavigationColor))
- )
- ],
- currentIndex: curIndex,
- onTap: (int index) {
- setState(() {
- curIndex = index;
- });
- },
- fixedColor: Colors.blue,
- type: BottomNavigationBarType.fixed,
- ),
- ),
- );
- }
- }
|