5_flutter_DropdownButton(下拉按钮),SliverAppBar(折叠工具栏),启动页面

1_DropdownButton(下拉按钮)


import 'package:flutter/material.dart';

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

class MyApp extends StatefulWidget {
  @override
  State createState() {
    return MyAppState();
  }
}

class MyAppState extends State {
  List _fruits = ["Apple", "Banana", "Pineapple", "Mango", "Grapes"];

  List> _dropDownMenuItems;
  String _selectedFruit;

  @override
  void initState() {
    _dropDownMenuItems = buildAndGetDropDownMenuItems(_fruits);
    _selectedFruit = _dropDownMenuItems[0].value;
    super.initState();
  }

  List> buildAndGetDropDownMenuItems(List fruits) {
    List> items = List();
    for (String fruit in fruits) {
      items.add(DropdownMenuItem(value: fruit, child: Text(fruit)));
    }
    return items;
  }

  void changedDropDownItem(String selectedFruit) {
    setState(() {
      _selectedFruit = selectedFruit;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          title: Text("DropDown Button Example"),
        ),
        body: Container(
          child: Center(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text("Please choose a fruit: "),
                  DropdownButton(
                    value: _selectedFruit,
                    items: _dropDownMenuItems,
                    onChanged: changedDropDownItem,
                  )
                ],
              )),
        ),
      ),
    );
  }
}
复制代码

2_SliverAppBar(折叠工具栏)


import 'package:flutter/material.dart';

void main() => runApp(MaterialApp(
  debugShowCheckedModeBanner: false,
  home: HomePage(),
));

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        slivers: [
          SliverAppBar(
            expandedHeight: 150.0,
            floating: false,
            pinned: true,
            flexibleSpace: FlexibleSpaceBar(
              title: Text("Sliver App Bar"),
            ),
          ),
          SliverFixedExtentList(
            itemExtent: 150.0,
            delegate:
            SliverChildBuilderDelegate((context, index) => ListTile(
              title: Text("List item $index"),
            )),
          )
        ],
      ),
    );
  }
}
复制代码

3_启动页面


android\app\src\main\res\drawable\launch_background.xml

  
     
        "center"
            android:src="@mipmap/ic_launcher" />
    
复制代码

转载于:https://juejin.im/post/5c7955c8f265da2dad300062

你可能感兴趣的:(5_flutter_DropdownButton(下拉按钮),SliverAppBar(折叠工具栏),启动页面)