• 城市选择选择 / 三级联动


    1.

    city_pickers: ^0.1.9
    

      

    import 'package:city_pickers/city_pickers.dart';
    

    2. 

    class TabsPage extends StatefulWidget{
      @override
      _TabsPageState createState() => new _TabsPageState();
    }
    
    class _TabsPageState extends State<TabsPage> with SingleTickerProviderStateMixin{
      TabController _tabController;
      String cityName;
    
      //初始化,一加载便会触发该方法
      void initState(){
        cityName='杭州';
        super.initState();
        _tabController = new TabController(
          vsync: this,
          length: 2,
        );
      }
    
    Widget build(BuildContext context){
        //初始化
        ScreenUtil.instance = ScreenUtil( 750, height: 1334)..init(context);
        return DefaultTabController(
          length: 2,
          child: Scaffold(
            appBar: appBar(),
          ),
        );
      }
         
          Widget appBar(){
        return AppBar(
           centerTitle: true,
            leading: Builder(
                builder: (context) => GestureDetector(
                  child: Padding(
                    padding: EdgeInsets.all(8.0),
                    child: IconButton(
                      icon: Icon(Icons.person),
                      onPressed: null,
                    )
                  ),
                  onTap: () => Scaffold.of(context).openDrawer(),
                ),
              ),
    
            title: Container(
              child:  FlatButton(
                // color: Colors.yellow,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Text(
                      '$cityName',
                      style: TextStyle(
                        color: Colors.black,
                        fontSize: ScreenUtil.getInstance().setSp(30)
                      ),
                      textAlign: TextAlign.left,
                    ),
                    IconButton(
                      alignment: Alignment.centerLeft,
                      icon: Icon(
                        Icons.arrow_drop_down, 
                        color: Color.fromRGBO(46, 48, 56, 1),
                      ),
                      onPressed: (){
                        debugPrint('down');
                      },
                    )
                  ],
                ),
                onPressed: (){
                  show(context);
                },
              ),
            ),
          );
      }
    
      //调用三级联动
      show(BuildContext context) async {
        //Result result = await CityPickers.showCityPicker(
          //context: context,
        //);
      
      //城市列表
       Result result = await CityPickers.showCitiesSelector(
        context: context,
       );

    print(result); setState(() { this.cityName = result.cityName; }); } }

      

      

  • 相关阅读:
    Silverlight 游戏开发小技巧:扇形排列元素
    Silverlight C# 游戏开发:L9 天空盒
    快乐技术开发者沙龙银光聚会第二期
    Silverlight 游戏开发小技巧:动感弹出动画
    Silverlight 游戏开发:可重用的拖拽控件
    获微软MVP
    Silverlight 游戏开发小技巧:动感小菜单1
    Protobuf语言指南
    使用xrdp或Xmanager 远程连接 CentOS6
    Linux 下使用 NMON 分析系统性能(其他如dstat、iostat)
  • 原文地址:https://www.cnblogs.com/xhrr/p/11425608.html
Copyright © 2020-2023  润新知