address_list.dart 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import 'package:flutter/material.dart';
  2. import 'package:provider/provider.dart';
  3. import 'package:twong/api/index.dart';
  4. import 'package:twong/router/base.dart';
  5. import 'package:twong/utils/index.dart';
  6. import 'package:twong/config/style.dart';
  7. import 'package:twong/models/index.dart';
  8. import 'package:twong/widgets/address_item.dart';
  9. import 'package:twong/widgets/app_bar.dart';
  10. import 'package:twong/providers/address.dart';
  11. class AddressPage extends StatefulWidget {
  12. @override
  13. State<StatefulWidget> createState() {
  14. return _AddressPageState();
  15. }
  16. }
  17. class _AddressPageState extends State<AddressPage> {
  18. @override
  19. void initState() {
  20. super.initState();
  21. loadData();
  22. }
  23. void loadData() {
  24. Network.inst.getAddressList().then((value){
  25. Log.d(value);
  26. Provider.of<AddressModel>(context, listen: false).set(value);
  27. });
  28. }
  29. @override
  30. Widget build(BuildContext context) {
  31. return Scaffold(
  32. appBar: DAppBar("地址管理", actions: [
  33. InkWell(
  34. onTap: _newAddress,
  35. highlightColor: Colors.transparent,
  36. child: Container(
  37. margin: EdgeInsets.only(right: 12.px),
  38. alignment: Alignment.center,
  39. child: Text("添加新地址"),
  40. ),
  41. )
  42. ]),
  43. body: SafeArea(
  44. child: Container(
  45. color: DColors.back,
  46. child: Consumer<AddressModel>(
  47. builder: (context, model, child) => _buildAddressList(model.list),
  48. ),
  49. ),
  50. ),
  51. bottomNavigationBar: SafeArea(
  52. child: Container(
  53. height: 50.px,
  54. decoration: BoxDecoration(
  55. color: Colors.white,
  56. boxShadow: DShadow.top,
  57. ),
  58. padding: EdgeInsets.only(top: 6.px, bottom: 12.px),
  59. child: InkWell(
  60. onTap: _newAddress,
  61. child: Container(
  62. decoration: BoxDecoration(
  63. color: DColors.Main,
  64. borderRadius: BorderRadius.circular(45.px),
  65. ),
  66. alignment: Alignment.center,
  67. margin: EdgeInsets.only(left: 22.px, right: 22.px),
  68. child: Row(
  69. mainAxisAlignment: MainAxisAlignment.center,
  70. children: [
  71. Icon(Icons.room_outlined, color: Colors.white),
  72. Text("新建收货地址", style: TextStyle(color: Colors.white))
  73. ],
  74. ),
  75. ),
  76. ),
  77. ),
  78. ),
  79. );
  80. }
  81. Widget _buildAddressList(List<Address> list) {
  82. if(list == null) {
  83. return Center(child: Utils.loadingWidget);
  84. }
  85. List<Widget> widgets = List<Widget>();
  86. for(var item in list) {
  87. widgets.add(Container(
  88. decoration: BoxDecoration(
  89. color: Colors.white,
  90. borderRadius: BorderRadius.circular(6.px)
  91. ),
  92. width: double.infinity,
  93. padding: EdgeInsets.all(6.px),
  94. margin: EdgeInsets.only(left: 12.px, right: 12.px,
  95. top: 6.px, bottom: 6.px),
  96. child: AddressItem(item),
  97. ));
  98. }
  99. return ListView(
  100. physics: ClampingScrollPhysics(),
  101. children: widgets,
  102. );
  103. }
  104. _newAddress() {
  105. Navigator.pushNamed(context, RouteNames.editAddress);
  106. }
  107. }