Flutter AppBar组件

2020-07-28  本文已影响0人  喜剧收尾_XWX
import 'package:flutter/material.dart';

void main() => runApp(Myapp());

class Myapp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      title: 'MaterialApp',
      home: HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build

    return Scaffold(
      appBar: AppBar(
        title: Text('MaterialApp'),
        //左侧图标
        leading: Icon(Icons.home),
        //右侧图标按钮
        actions: <Widget>[
          IconButton(
            icon: Icon(Icons.add),
            tooltip: '添加',
            onPressed: () {
              print("添加");
            },
          ),
          IconButton(
            icon: Icon(Icons.search),
            tooltip: '搜索',
            onPressed: () {
              print("搜索");
            },
          ),
        ],
      ),
      body: Center(
        child: Text('MaterialApp'),
      ),
      bottomNavigationBar: BottomAppBar(
        child: Container(
          height: 50,
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {},
        tooltip: '增加',
        child: Icon(Icons.add),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
    );
  }
}

效果图
上一篇 下一篇

猜你喜欢

热点阅读