基础组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wallet_page.dart 5.0 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:provider/provider.dart';
  4. import 'package:pull_to_refresh/pull_to_refresh.dart';
  5. import 'package:zhiying_base_widget/pages/main_page/notifier/main_page_bg_notifier.dart';
  6. import 'package:zhiying_base_widget/pages/main_page/notifier/main_page_notifier.dart';
  7. import 'package:zhiying_base_widget/utils/contants.dart';
  8. import 'package:zhiying_base_widget/widgets/others/mine_header_bg_widget.dart';
  9. import 'package:zhiying_comm/zhiying_comm.dart';
  10. import 'package:zhiying_comm/util/base_bloc.dart';
  11. import 'package:zhiying_comm/util/custom_sliver_persistent_header_delegate.dart';
  12. import 'wallet_page_bloc.dart';
  13. import 'wallet_page_bloc.dart';
  14. class WalletPage extends StatefulWidget {
  15. final Map<String, dynamic> data;
  16. const WalletPage({Key key, this.data}) : super(key: key);
  17. @override
  18. _WalletPageState createState() => _WalletPageState();
  19. }
  20. class _WalletPageState extends State<WalletPage> {
  21. @override
  22. Widget build(BuildContext context) {
  23. return Scaffold(
  24. backgroundColor: Color(0xfff9f9f9),
  25. body: MultiProvider(
  26. providers: [
  27. ChangeNotifierProvider.value(value: MainPageNotifier()),
  28. ChangeNotifierProvider.value(value: MainPageBgNotifier()),
  29. ],
  30. child: BlocProvider<WalletPageBloc>(
  31. bloc: WalletPageBloc(),
  32. child: _WalletPageContainer(data: widget.data),
  33. ),
  34. ),
  35. );
  36. }
  37. }
  38. class _WalletPageContainer extends StatefulWidget {
  39. _WalletPageContainer({Key key, this.data}) : super(key: key);
  40. final Map<String, dynamic> data;
  41. @override
  42. _WalletPageContainerState createState() => _WalletPageContainerState();
  43. }
  44. class _WalletPageContainerState extends State<_WalletPageContainer> {
  45. final ScrollController _controller = ScrollController();
  46. final RefreshController _refreshController =
  47. RefreshController(initialRefresh: false);
  48. WalletPageBloc _pageBloc;
  49. @override
  50. void initState() {
  51. _pageBloc = BlocProvider.of<WalletPageBloc>(context);
  52. if (widget.data.containsKey(Constants.SkipIdentifierName)) {
  53. _pageBloc.loadData(widget.data[Constants.SkipIdentifierName]);
  54. }
  55. super.initState();
  56. }
  57. void _onLoading() async {
  58. // await Future.delayed(Duration(milliseconds: 1000));
  59. // if (mounted) setState(() {});
  60. // _refreshController.loadComplete();
  61. }
  62. @override
  63. Widget build(BuildContext context) {
  64. ScreenUtil.init(context, width: 750, height: 1334);
  65. return SmartRefresher(
  66. controller: _refreshController,
  67. enablePullDown: false,
  68. enablePullUp: false,
  69. header: WaterDropHeader(),
  70. onLoading: _onLoading,
  71. child: Container(
  72. width: double.infinity,
  73. child: Stack(
  74. fit: StackFit.passthrough,
  75. children: <Widget>[
  76. MineHeaderBgWidget(
  77. controller: _controller,
  78. ),
  79. StreamBuilder(
  80. stream: _pageBloc.outData,
  81. builder: (context, asyncSnapshot) {
  82. var model = asyncSnapshot.data;
  83. return CustomScrollView(
  84. slivers: _createContent(context, model),
  85. );
  86. },
  87. )
  88. ],
  89. ),
  90. ),
  91. );
  92. }
  93. List<Widget> _createContent(
  94. BuildContext context, List<Map<String, dynamic>> model) {
  95. List<Widget> list = List();
  96. if (model == null) {
  97. list.addAll(WidgetFactory.create(
  98. 'normal_nav',
  99. isSliver: true,
  100. model: Map(),
  101. ));
  102. list.addAll(WidgetFactory.create(
  103. 'wallet_data',
  104. isSliver: true,
  105. model: Map(),
  106. ));
  107. list.addAll(WidgetFactory.create(
  108. 'wallet_detail',
  109. isSliver: true,
  110. model: Map(),
  111. ));
  112. list.addAll(WidgetFactory.create(
  113. 'wallet_income',
  114. isSliver: true,
  115. model: Map(),
  116. ));
  117. } else {
  118. for (var item in model) {
  119. WidgetModel widgetModel =
  120. WidgetModel.fromJson(Map<String, dynamic>.from(item));
  121. if (item.containsKey("mod_name")&&item['mod_name']=="my_wallet_appbar") {
  122. list.add(SliverPersistentHeader(
  123. delegate: _SilverAppBarDelegate(context,
  124. WidgetFactory.create(widgetModel.modName,
  125. isSliver: false, model: item)[0]),pinned: true,));
  126. continue;
  127. }
  128. list.addAll(WidgetFactory.create(widgetModel.modName,
  129. isSliver: true, model: item));
  130. }
  131. }
  132. return list;
  133. }
  134. }
  135. class _SilverAppBarDelegate extends SliverPersistentHeaderDelegate {
  136. _SilverAppBarDelegate(BuildContext context,this.child){
  137. this.context=context;
  138. }
  139. BuildContext context;
  140. final Widget child;
  141. @override
  142. double get minExtent => MediaQuery.of(context).padding.top+44;
  143. @override
  144. double get maxExtent => MediaQuery.of(context).padding.top+44;
  145. @override
  146. Widget build(
  147. BuildContext context, double shrinkOffset, bool overlapsContent) {
  148. return child;
  149. }
  150. @override
  151. bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) {
  152. return false;
  153. }
  154. }