基础组件库
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.

guide_page.dart 9.0 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import 'dart:io';
  2. import 'dart:typed_data';
  3. import 'package:flutter/material.dart';
  4. import 'package:zhiying_base_widget/dialog/global_dialog/policy_dialog/policy_dialog.dart';
  5. import 'package:zhiying_base_widget/models/app_config_model.dart';
  6. import 'package:flutter_swiper/flutter_swiper.dart';
  7. import 'package:zhiying_base_widget/utils/contants.dart';
  8. import 'package:zhiying_base_widget/widgets/home/home_quick_entry/cached_network_image_util.dart';
  9. import 'package:zhiying_comm/util/shared_prefe_util.dart';
  10. import 'package:zhiying_comm/zhiying_comm.dart';
  11. import 'package:zhiying_base_widget/utils/over_scroll_behavior.dart' as Scroll;
  12. class GuidePage extends StatefulWidget {
  13. final GuideData model;
  14. final List<Uint8List> imageDatas;
  15. final List<Uint8List> bgImageDatas;
  16. const GuidePage(this.model, this.imageDatas, this.bgImageDatas, {Key key}) : super(key: key);
  17. @override
  18. State<StatefulWidget> createState() => _GuidePageState();
  19. }
  20. class _GuidePageState extends State<GuidePage> {
  21. @override
  22. void initState() {
  23. Future.delayed(Duration(milliseconds: 100), () {
  24. showPlolicy();
  25. });
  26. super.initState();
  27. }
  28. @override
  29. Widget build(BuildContext context) {
  30. List<int> list = List.generate(widget.imageDatas?.length, (index) => index);
  31. return WillPopScope(
  32. onWillPop: () async => false, // 拦截Android返回键
  33. child: Material(
  34. color: Colors.white,
  35. child: Theme(
  36. data: ThemeData(splashFactory: NoSplashFactory()),
  37. child: ScrollConfiguration(
  38. behavior: Scroll.OverScrollBehavior(),
  39. child: Swiper(
  40. physics: ClampingScrollPhysics(),
  41. itemBuilder: (BuildContext context, int index) {
  42. // return CachedNetworkImage(imageUrl: widget.model.images[index],fit: BoxFit.cover,);
  43. Uint8List bgImage;
  44. if (widget.bgImageDatas.length > index) {
  45. bgImage = widget?.bgImageDatas[index];
  46. }
  47. return Stack(
  48. alignment: Alignment.center,
  49. children: <Widget>[
  50. Container(
  51. width: double.infinity,
  52. height: double.infinity,
  53. decoration: BoxDecoration(
  54. image: DecorationImage(
  55. image: bgImage != null
  56. ? Image.memory(
  57. bgImage,
  58. ).image
  59. : CachedNetworkImageProvider(""),
  60. fit: BoxFit.fill)),
  61. child: Center(
  62. child: widget.imageDatas[index] != null
  63. ? Image.memory(
  64. widget.imageDatas[index],
  65. fit: BoxFit.fitWidth,
  66. )
  67. : Container(
  68. color: Colors.white,
  69. ))),
  70. index == widget?.bgImageDatas?.length - 1
  71. ? Positioned(
  72. left: 0,
  73. right: 0,
  74. bottom: 110,
  75. child: Center(
  76. child: Row(
  77. mainAxisAlignment: MainAxisAlignment.center,
  78. children: <Widget>[
  79. Container(
  80. alignment: Alignment.center,
  81. height: 46,
  82. width: 180,
  83. decoration: BoxDecoration(
  84. color: HexColor.fromHex(widget?.model?.btnBgColor ?? ""),
  85. borderRadius: BorderRadius.circular(45),
  86. boxShadow: [BoxShadow(color: HexColor.fromHex(widget?.model?.btnBgColor), offset: Offset(1, 2), blurRadius: 6)]),
  87. child: Text(
  88. widget?.model?.btnText ?? "",
  89. style: TextStyle(color: HexColor.fromHex(widget?.model?.btnTextColor ?? ""), fontSize: 16, height: 1.1),
  90. ),
  91. ),
  92. ],
  93. ),
  94. ),
  95. )
  96. : Container()
  97. ],
  98. );
  99. },
  100. loop: false,
  101. itemCount: widget.imageDatas?.length ?? 0,
  102. pagination: widget?.model?.indicatorType != "1"
  103. ? null
  104. : widget?.model?.indicatorCssType == "2"
  105. ? SwiperCustomPagination(builder: (BuildContext context, SwiperPluginConfig config) {
  106. return Align(
  107. alignment: Alignment(0.0, 1),
  108. child: Row(
  109. mainAxisAlignment: MainAxisAlignment.center,
  110. crossAxisAlignment: CrossAxisAlignment.center,
  111. children: list.map((index) {
  112. return SafeArea(
  113. child: Container(
  114. margin: EdgeInsets.only(bottom: 40, left: 5, right: 5),
  115. height: 4,
  116. width: 20,
  117. decoration: BoxDecoration(
  118. borderRadius: BorderRadius.circular(10),
  119. color: index == config.activeIndex
  120. ? HexColor.fromHex(widget?.model?.indicatorChooseColor)
  121. : HexColor.fromHex(widget?.model?.indicatorUnchooseColor)),
  122. ),
  123. );
  124. }).toList(),
  125. ),
  126. );
  127. })
  128. : SwiperCustomPagination(builder: (BuildContext context, SwiperPluginConfig config) {
  129. return Align(
  130. alignment: Alignment(0.0, 1),
  131. child: Row(
  132. mainAxisAlignment: MainAxisAlignment.center,
  133. crossAxisAlignment: CrossAxisAlignment.center,
  134. children: list.map((index) {
  135. return SafeArea(
  136. child: Container(
  137. margin: EdgeInsets.only(bottom: 40, left: 5, right: 5),
  138. height: 10,
  139. width: 10,
  140. decoration: BoxDecoration(
  141. borderRadius: BorderRadius.circular(10),
  142. color: index == config.activeIndex
  143. ? HexColor.fromHex(widget?.model?.indicatorChooseColor)
  144. : HexColor.fromHex(widget?.model?.indicatorUnchooseColor)),
  145. ),
  146. );
  147. }).toList(),
  148. ),
  149. );
  150. }),
  151. onIndexChanged: (index) {},
  152. onTap: (index) {
  153. if (index == widget.model.guideCss.length - 1) {
  154. Navigator.pop(context, true);
  155. }
  156. },
  157. ),
  158. ),
  159. ),
  160. ),
  161. );
  162. }
  163. void showPlolicy() async {
  164. ///协议弹窗
  165. String isShowPolicy = await SharedPreferencesUtil.getStringValue(Constants.isShowPolicy);
  166. if (isShowPolicy == null || isShowPolicy != '1') {
  167. NativeUtil.notifyInitSuccess();
  168. bool isAccept = await PolicyDialog.show(context);
  169. if (!isAccept) {
  170. exit(0);
  171. } else {
  172. await SharedPreferencesUtil.setStringValue(Constants.isShowPolicy, "1");
  173. }
  174. }
  175. }
  176. }
  177. class NoSplashFactory extends InteractiveInkFeatureFactory {
  178. InteractiveInkFeature create(
  179. {MaterialInkController controller,
  180. RenderBox referenceBox,
  181. Offset position,
  182. Color color,
  183. TextDirection textDirection,
  184. bool containedInkWell = false,
  185. rectCallback,
  186. BorderRadius borderRadius,
  187. ShapeBorder customBorder,
  188. double radius,
  189. onRemoved}) {
  190. return _NoInteractiveInkFeature(controller: controller, referenceBox: referenceBox);
  191. }
  192. }
  193. class _NoInteractiveInkFeature extends InteractiveInkFeature {
  194. _NoInteractiveInkFeature({
  195. MaterialInkController controller,
  196. RenderBox referenceBox,
  197. }) : super(controller: controller, referenceBox: referenceBox);
  198. void paintFeature(Canvas canvas, Matrix4 transform) {}
  199. }