flutter3

import 'package:flutter/material.dart';

void main() {
  runApp(const GoWaterMyApp());
}

class GoWaterMyApp extends StatelessWidget {
  const GoWaterMyApp({super.key});
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'GoWater',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.lightBlue),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: '桶装水自动配送系统'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  late int _selectedIndex = 0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
        elevation: 30.0, //阴影默认4.0

        leading: IconButton(
            icon: const Icon(Icons.menu),
            tooltip: 'Navigation',
            onPressed: () => debugPrint('Navigation button is pressed')),

        actions: <Widget>[
          //actions: <Widget>里可以设置一组小部件
          IconButton(
              icon: Icon(Icons.search),
              tooltip: 'search',
              onPressed: () => debugPrint('搜索')),
          IconButton(
              icon: const Icon(Icons.more_horiz),
              tooltip: 'more_horiz',
              onPressed: () => debugPrint('更多')),
        ],
      ),
      body: SafeArea(
        child: Container(),
      ),
//导航开始
      bottomNavigationBar: BottomNavigationBar(
        selectedItemColor: Colors.lightBlue,
        currentIndex: _selectedIndex,
        onTap: (index) => setState(() {
          _selectedIndex = index;
        }),
        //如果超过宽度则必须加下面这句
        type: BottomNavigationBarType.fixed,
        //fixedColor: Colors.black, //激活状态的颜色
        items: const [
          BottomNavigationBarItem(
            icon: Icon(Icons.list),
            label: '历史',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.widgets),
            label: '订水',
          ),
          BottomNavigationBarItem(icon: Icon(Icons.history), label: ('发现')),
          BottomNavigationBarItem(
            icon: Icon(Icons.settings),
            label: '自己',
          ),
        ],
      ),
//导航结束
    );
  }
}

  

posted @ 2024-07-01 14:54  飞雪飘鸿  阅读(2)  评论(0编辑  收藏  举报
https://damo.alibaba.com/ https://tianchi.aliyun.com/course?spm=5176.21206777.J_3941670930.5.87dc17c9BZNvLL