zoukankan      html  css  js  c++  java
  • 底部不规则导航栏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],//内容对象,根据按钮的索引改变 改变布局内容

     

     
  • 相关阅读:
    使用CustomValidate自定义验证控件
    C#中金额的大小写转换
    Andriod出错之Unable to build: the file dx.jar was not loaded from the SDK folder!
    VC 编写的打字练习
    机房工作笔记Ping只有单向通
    web服务协同学习笔记(1)
    Dll 学习3 将MDI子窗口封装在DLL中
    机房工作学习文件共享
    Andriod出错之Failed to find an AVD compatible with target 'Android 2.2'
    Andriod出错之wrapper was not properly loaded first
  • 原文地址:https://www.cnblogs.com/pp-pping/p/12175302.html
Copyright © 2011-2022 走看看