基础组件库
 
 
 
 
 

145 lines
6.3 KiB

  1. import 'dart:typed_data';
  2. import 'package:flutter/material.dart';
  3. import 'package:zhiying_base_widget/models/app_config_model.dart';
  4. import 'package:flutter_swiper/flutter_swiper.dart';
  5. import 'package:zhiying_base_widget/widgets/home/home_quick_entry/cached_network_image_util.dart';
  6. import 'package:zhiying_comm/zhiying_comm.dart';
  7. class GuidePage extends StatefulWidget {
  8. final GuideData model;
  9. final List<Uint8List> imageDatas;
  10. final List<Uint8List> bgImageDatas;
  11. const GuidePage(this.model, this.imageDatas, this.bgImageDatas, {Key key}) : super(key: key);
  12. @override
  13. State<StatefulWidget> createState() => _GuidePageState();
  14. }
  15. class _GuidePageState extends State<GuidePage> {
  16. @override
  17. Widget build(BuildContext context) {
  18. bool isShowIndicator = (widget.model?.indicatorType ?? '0') == '1';
  19. List<int> list = List.generate(widget.imageDatas?.length, (index) => index);
  20. return WillPopScope(
  21. onWillPop: () async => false, // 拦截Android返回键
  22. child: Material(
  23. child: Swiper(
  24. itemBuilder: (BuildContext context, int index) {
  25. // return CachedNetworkImage(imageUrl: widget.model.images[index],fit: BoxFit.cover,);
  26. Uint8List bgImage;
  27. if (widget.bgImageDatas.length > index) {
  28. bgImage = widget?.bgImageDatas[index];
  29. }
  30. return Stack(
  31. alignment: Alignment.center,
  32. children: <Widget>[
  33. Container(
  34. width: double.infinity,
  35. height: double.infinity,
  36. decoration: BoxDecoration(
  37. image: DecorationImage(
  38. image: Image.memory(
  39. bgImage,
  40. ).image,
  41. fit: BoxFit.fill)),
  42. child: Center(
  43. child: Image.memory(
  44. widget.imageDatas[index],
  45. fit: BoxFit.fitWidth,
  46. ))),
  47. index == widget?.bgImageDatas?.length - 1
  48. ? Positioned(
  49. left: 0,
  50. right: 0,
  51. bottom: 110,
  52. child: Center(
  53. child: Row(
  54. mainAxisAlignment: MainAxisAlignment.center,
  55. children: <Widget>[
  56. Container(
  57. alignment: Alignment.center,
  58. height: 46,
  59. width: 180,
  60. decoration: BoxDecoration(
  61. color: HexColor.fromHex(widget?.model?.btnBgColor ?? ""),
  62. borderRadius: BorderRadius.circular(45),
  63. boxShadow: [BoxShadow(color: HexColor.fromHex(widget?.model?.btnBgColor), offset: Offset(1, 2), blurRadius: 6)]),
  64. child: Text(
  65. widget?.model?.btnText ?? "",
  66. style: TextStyle(color: HexColor.fromHex(widget?.model?.btnTextColor ?? ""), fontSize: 16, height: 1.1),
  67. ),
  68. ),
  69. ],
  70. ),
  71. ),
  72. )
  73. : Container()
  74. ],
  75. );
  76. },
  77. loop: false,
  78. itemCount: widget.imageDatas?.length ?? 0,
  79. pagination: widget?.model?.indicatorType != "1"
  80. ? null
  81. : widget?.model?.indicatorCssType == "2"
  82. ? SwiperCustomPagination(builder: (BuildContext context, SwiperPluginConfig config) {
  83. return Align(
  84. alignment: Alignment(0.0, 1),
  85. child: Row(
  86. mainAxisAlignment: MainAxisAlignment.center,
  87. crossAxisAlignment: CrossAxisAlignment.center,
  88. children: list.map((index) {
  89. return SafeArea(
  90. child: Container(
  91. margin: EdgeInsets.only(bottom: 40, left: 5, right: 5),
  92. height: 4,
  93. width: 20,
  94. decoration: BoxDecoration(
  95. borderRadius: BorderRadius.circular(10),
  96. color: index == config.activeIndex
  97. ? HexColor.fromHex(widget?.model?.indicatorChooseColor)
  98. : HexColor.fromHex(widget?.model?.indicatorUnchooseColor)),
  99. ),
  100. );
  101. }).toList(),
  102. ),
  103. );
  104. })
  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: 10,
  116. width: 10,
  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. onIndexChanged: (index) {},
  129. onTap: (index) {
  130. if (index == widget.model.guideCss.length - 1) {
  131. Navigator.pop(context, true);
  132. }
  133. },
  134. ),
  135. ),
  136. );
  137. }
  138. }