
import 'package:flutter/material.dart';
import 'package:twong/config/style.dart';
import 'package:twong/models/address.dart';

import 'package:twong/utils/index.dart';
import 'package:twong/widgets/address_selecter.dart';
import 'package:twong/widgets/app_bar.dart';

class EditAddressPage extends StatefulWidget {
  final dynamic data;

  EditAddressPage(this.data);

  @override
  State<StatefulWidget> createState() {
    return _EditAddressPageState();
  }
}

class _EditAddressPageState extends State<EditAddressPage> {
  Address _address = Address();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: DAppBar(widget.data == null ? "添加收货地址" : "编辑收货地址"),
      body: SafeArea(
        child: Container(
          margin: EdgeInsets.all(12.px),
          child: ListView(
            children: [
              Container(child: Row(
                children: [
                  Text("姓名"),
                ],
              )),
              Divider(),
              Text("联系电话"),
              Divider(),
              Text("所在区域"),
              Divider(),
              Text("详细地址"),
              Divider(),
              FlatButton(
                color: DColors.Main,
                shape: StadiumBorder(),
                child: Text("立即保存", style: TextStyle(color: Colors.white)),
                onPressed: () {
                  Navigator.pop(context, _address);
                },
              )
            ],
          ),
        ),
      ),
    );
  }

  void _choiceAddressDialog() async {
    showModalBottomSheet(
        context: context,
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.only(
            topLeft: Radius.circular(10.px), topRight: Radius.circular(10.px)
        )),
        builder: (BuildContext context) {
          return AddressSelecter(
              onSelected: (province, city, county) {
                print('$province-$city-$county');
                _address.province = province;
                _address.city = city;
                _address.district = county;
                // _address = '$province-$city-$county';
                setState(() {});
              },
              title: '选择地址',
              selectedColor: Colors.red,
              unselectedColor: Colors.black);
        });
  }
}