• 底部不规则导航栏2


    代码1:

    动态布局基础文件

    import 'package:flutter/material.dart';
    class EveryPage extends StatefulWidget {
    String _title;
    EveryPage(this._title);
    @override
    _EveryPageState createState() => _EveryPageState();
    }

    class _EveryPageState extends State<EveryPage> {
    @override
    Widget build(BuildContext context) {
    return Scaffold(
    appBar: AppBar(title: Text(widget._title),),
    body: Center(
    child: Text(widget._title),
    ),
    );
    }
    }
    代码2:实现内容
    import 'package:flutter/material.dart';
    import 'every_page.dart';
    class BottomAppBarDemo extends StatefulWidget {


    @override
    _BottomAppBarDemoState createState() => _BottomAppBarDemoState();
    }

    class _BottomAppBarDemoState extends State<BottomAppBarDemo> {
    List<Widget> _everyPage;
    int _index = 0;
    @override
    void initState(){
    _everyPage = List();
    _everyPage..add(EveryPage('hone'))..add(EveryPage('Email'));
    super.initState();
    }
    @override
    Widget build(BuildContext context) {
     
    return Scaffold(
    body: _everyPage[_index],
    floatingActionButton: FloatingActionButton(
    onPressed: (){
    Navigator.of(context).push(
    MaterialPageRoute(builder: (BuildContext context){
    return EveryPage('Photo');
    })
    );
    },
    tooltip: '创建',
    child: Icon(
    Icons.add_a_photo,
    color: Colors.white,
    ),
    ),
    floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
    bottomNavigationBar: BottomAppBar(
    color: Colors.orange,
    shape: CircularNotchedRectangle(),
    child: Row(
    mainAxisSize: MainAxisSize.max,
    mainAxisAlignment: MainAxisAlignment.spaceAround,
    children: <Widget>[
    IconButton(
    icon: Icon(Icons.home),
     
    color: Colors.white,
     
    onPressed: (){
    setState(() {
    _index = 0;
    });
    },
    ), IconButton(
    icon: Icon(Icons.hotel),
    color: Colors.white,
    onPressed: (){
    setState(() {
    _index = 1;
    });
    },
    )
    ],
    ),
    ),
    );
    }
    }
    总结:
     

    不规则底部导航栏2

     

    创建动态widget

    class 类名 extends StatefulWidget {

      String _title;

      EveryPage(this._title);

      @override

      _EveryPageState createState() => _EveryPageState();

    }

    class _EveryPageState extends State<EveryPage> {

      @override

      Widget build(BuildContext context) {

        return Scaffold(

          appBar: AppBar(title: Text(widget._title),),//此处的widget 应该是一个内置对象获得上面的类对象

          body: Center(

            child: Text(widget._title),

          ),

        );

      }

    重写State

    List<widget> _集合对象1

    Void initState(){

    _集合对象1 = List();

    _集合对象1..add(类名(参数))//返回的还是集合 等于 list = [list add:xxx];

     

    }

     

    IconButton(

    onpressed:()

    setState((

    _index =xx;//改变状态索引

    ))

    {}

     

    )

    body: _everyPage[_index],//内容对象,根据按钮的索引改变 改变布局内容

     

     
  • 相关阅读:
    旋转骰子
    自我介绍
    【边带权 维护节点和根距离 两点距离】银河英雄传说
    【含义冲突判断】程序自动分析
    【01背包 合并费用】搭配购买
    【网格图环判断】格子游戏
    【连通块 维护size】 连通块中的点数
    【模板】 合并集合
    【出栈顺序判断】 Rails
    【整除分块】 余数之和
  • 原文地址:https://www.cnblogs.com/pp-pping/p/12175302.html
Copyright © 2020-2023  润新知