码迷,mamicode.com
首页 > 其他好文 > 详细

地区选择-三级联动

时间:2019-08-28 18:37:11      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:center   leading   instance   caff   enter   erp   this   async   tin   

1.

city_pickers: ^0.0.1

  

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(width: 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,
    );
    print(result);
    setState(() {
     this.cityName = result.cityName; 
    });
  }
}

  

  

地区选择-三级联动

标签:center   leading   instance   caff   enter   erp   this   async   tin   

原文地址:https://www.cnblogs.com/xhrr/p/11425608.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!