address_bar.dart 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import 'package:flutter/material.dart';
  2. import 'package:provider/provider.dart';
  3. import 'package:twong/api/index.dart';
  4. import 'package:twong/config/style.dart';
  5. import 'package:twong/models/address.dart';
  6. import 'package:twong/providers/address.dart';
  7. import 'package:twong/router/index.dart';
  8. import 'package:twong/utils/index.dart';
  9. import 'package:twong/widgets/address_item.dart';
  10. class AddressBar extends StatefulWidget {
  11. final Address address;
  12. final Function(Address) onSelected;
  13. AddressBar({ this.onSelected, this.address });
  14. @override
  15. State<StatefulWidget> createState() {
  16. return _AddressState();
  17. }
  18. }
  19. class _AddressState extends State<AddressBar> {
  20. Address _address;
  21. @override
  22. void initState() {
  23. this._address = widget.address;
  24. super.initState();
  25. Network.inst.getAddressList().then((res) {
  26. Provider.of<AddressModel>(context, listen: false).set(res);
  27. });
  28. }
  29. @override
  30. Widget build(BuildContext context) {
  31. return SafeArea(child: Container(
  32. height: 380.px,
  33. child: ListView(
  34. physics: ClampingScrollPhysics(),
  35. children: [
  36. Stack(
  37. children: [
  38. Container(
  39. width: double.infinity,
  40. margin: EdgeInsets.only(top: 6.px, bottom: 6.px),
  41. child: Text("选择收货地址", style: TextStyle(fontSize:
  42. 16.px), textAlign: TextAlign.center)
  43. ),
  44. Positioned(
  45. top: 8.px,
  46. right: 12.px,
  47. child: InkWell(
  48. onTap: () => Navigator.pop(context),
  49. child: Icon(
  50. Icons.close, color: Colors.grey, size: 18.px),
  51. ))
  52. ],
  53. ),
  54. Consumer<AddressModel>(
  55. builder: (context, model, child) => _buildAddressList(model),
  56. )
  57. ],
  58. ),
  59. ));
  60. }
  61. Widget _buildAddressList(AddressModel model) {
  62. if(model.list == null) {
  63. return Center(child: Utils.loadingWidget);
  64. }
  65. List<Widget> widgets = List<Widget>();
  66. for(var item in model.list) {
  67. widgets.add(InkWell(
  68. onTap: () {
  69. if(widget.onSelected != null) {
  70. widget.onSelected(item);
  71. }
  72. Navigator.pop(context);
  73. },
  74. child: Container(
  75. // decoration: BoxDecoration(
  76. // borderRadius: BorderRadius.circular(12.px),
  77. // border: Border.all(color: _address?.id == item.id ? DColors.Main
  78. // : Colors.grey),
  79. // ),
  80. padding: EdgeInsets.all(6.px),
  81. margin: EdgeInsets.only(left: 12.px, right: 12.px),
  82. child: AddressItem(item),
  83. ),
  84. ));
  85. }
  86. return Column(
  87. children: [
  88. Container(
  89. height: 268.px,
  90. margin: EdgeInsets.only(top: 12.px),
  91. child: ListView(
  92. children: widgets,
  93. ),
  94. ),
  95. Container(
  96. height: 68.px,
  97. decoration: BoxDecoration(
  98. color: Colors.white,
  99. boxShadow: DShadow.top,
  100. ),
  101. padding: EdgeInsets.only(top: 6.px, bottom: 12.px),
  102. child: InkWell(
  103. onTap: () {
  104. Navigator.pushNamed(context, RouteNames.editAddress);
  105. },
  106. child: Container(
  107. decoration: BoxDecoration(
  108. color: DColors.Main,
  109. borderRadius: BorderRadius.circular(45.px),
  110. ),
  111. alignment: Alignment.center,
  112. margin: EdgeInsets.only(left: 22.px, right: 22.px, bottom: 8.px),
  113. child: Row(
  114. mainAxisAlignment: MainAxisAlignment.center,
  115. children: [
  116. Icon(Icons.room_outlined, color: Colors.white),
  117. Text("新建收货地址", style: TextStyle(color: Colors.white))
  118. ],
  119. ),
  120. ),
  121. ),
  122. )
  123. ],
  124. );
  125. }
  126. }