基础组件库
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 

183 wiersze
5.5 KiB

  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/refresh/refresh_header/refresh_header.dart';
  9. import 'package:zhiying_base_widget/widgets/wallet/wallet_appbar/wallet_appbar_sk.dart';
  10. import 'package:zhiying_base_widget/widgets/wallet/wallet_data/wallet_data_sk.dart';
  11. import 'package:zhiying_base_widget/widgets/wallet/wallet_detail/wallet_detail_sk.dart';
  12. import 'package:zhiying_base_widget/widgets/wallet/wallet_income/wallet_income_sk.dart';
  13. import 'package:zhiying_comm/util/base_bloc.dart';
  14. import 'package:zhiying_comm/zhiying_comm.dart';
  15. import 'dart:ui';
  16. import 'wallet_page_bloc.dart';
  17. ///钱包页面
  18. class WalletPage extends StatefulWidget {
  19. final Map<String, dynamic> data;
  20. const WalletPage({Key key, this.data}) : super(key: key);
  21. @override
  22. _WalletPageState createState() => _WalletPageState();
  23. }
  24. class _WalletPageState extends State<WalletPage> {
  25. @override
  26. Widget build(BuildContext context) {
  27. return Scaffold(
  28. backgroundColor: Color(0xfff9f9f9),
  29. body: MultiProvider(
  30. providers: [
  31. ChangeNotifierProvider.value(value: MainPageNotifier()),
  32. ChangeNotifierProvider.value(value: MainPageBgNotifier()),
  33. ],
  34. child: BlocProvider<WalletPageBloc>(
  35. bloc: WalletPageBloc(),
  36. child: _WalletPageContainer(data: widget.data),
  37. ),
  38. ),
  39. );
  40. }
  41. }
  42. class _WalletPageContainer extends StatefulWidget {
  43. _WalletPageContainer({Key key, this.data}) : super(key: key);
  44. final Map<String, dynamic> data;
  45. @override
  46. _WalletPageContainerState createState() => _WalletPageContainerState();
  47. }
  48. class _WalletPageContainerState extends State<_WalletPageContainer> {
  49. ScrollController _controller;
  50. RefreshController _refreshController;
  51. WalletPageBloc _pageBloc;
  52. @override
  53. void initState() {
  54. _controller = ScrollController();
  55. _refreshController = RefreshController(initialRefresh: false);
  56. _pageBloc = BlocProvider.of<WalletPageBloc>(context);
  57. if (widget.data.containsKey(Constants.SkipIdentifierName)) {
  58. _pageBloc.loadData(widget.data[Constants.SkipIdentifierName]);
  59. }
  60. super.initState();
  61. }
  62. @override
  63. void dispose() {
  64. _refreshController?.dispose();
  65. super.dispose();
  66. }
  67. void _onLoading() async {
  68. // await Future.delayed(Duration(milliseconds: 1000));
  69. // if (mounted) setState(() {});
  70. // _refreshController.loadComplete();
  71. }
  72. void _onRefresh() async {
  73. if (widget.data.containsKey(Constants.SkipIdentifierName)) {
  74. _pageBloc.loadData(widget.data[Constants.SkipIdentifierName]);
  75. }
  76. }
  77. @override
  78. Widget build(BuildContext context) {
  79. ScreenUtil.init(context, width: 750, height: 1334);
  80. double top = MediaQueryData.fromWindow(window).padding.top;
  81. return Container(
  82. width: double.infinity,
  83. child: Stack(
  84. fit: StackFit.passthrough,
  85. children: <Widget>[
  86. StreamBuilder(
  87. stream: _pageBloc.outData,
  88. builder: (context, asyncSnapshot) {
  89. var model = asyncSnapshot.data;
  90. _refreshController.refreshCompleted();
  91. return Stack(
  92. children: <Widget>[
  93. Container(height: 362.h, color: _pageBloc.backgroundColor),
  94. SmartRefresher(
  95. controller: _refreshController,
  96. enablePullDown: true,
  97. enablePullUp: false,
  98. header: RefreshHeader(
  99. offsetY: top,
  100. ),
  101. onLoading: _onLoading,
  102. onRefresh: _onRefresh,
  103. child: CustomScrollView(
  104. controller: _controller,
  105. slivers: _createContent(context, model),
  106. ),
  107. )
  108. ],
  109. );
  110. },
  111. )
  112. ],
  113. ),
  114. );
  115. }
  116. List<Widget> _createContent(BuildContext context, List<Map<String, dynamic>> model) {
  117. List<Widget> list = List();
  118. if (model == null) {
  119. ///骨架图
  120. list.add(SliverToBoxAdapter(
  121. child: WalletAppbarSkeleton(),
  122. ));
  123. list.add(SliverToBoxAdapter(
  124. child: WalletDataSkeleton(),
  125. ));
  126. list.add(SliverToBoxAdapter(
  127. child: WalletIncomeSkeleton(),
  128. ));
  129. list.add(SliverToBoxAdapter(
  130. child: WalletDetailSkeleton(),
  131. ));
  132. } else {
  133. for (var item in model) {
  134. WidgetModel widgetModel = WidgetModel.fromJson(Map<String, dynamic>.from(item));
  135. list.addAll(WidgetFactory.create(widgetModel.modName, isSliver: true, model: item));
  136. }
  137. }
  138. return list;
  139. }
  140. }
  141. class _SilverAppBarDelegate extends SliverPersistentHeaderDelegate {
  142. _SilverAppBarDelegate(BuildContext context, this.child) {
  143. this.context = context;
  144. }
  145. BuildContext context;
  146. final Widget child;
  147. @override
  148. double get minExtent => MediaQuery.of(context).padding.top + 44;
  149. @override
  150. double get maxExtent => MediaQuery.of(context).padding.top + 44;
  151. @override
  152. Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
  153. return child;
  154. }
  155. @override
  156. bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) {
  157. return false;
  158. }
  159. }