AppNotice.dart 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:wanna_battle/net/HttpManager.dart';
  4. Future getAppNotice(context) async {
  5. final res = await HttpManager.get('systemVariable/getOne', data: {
  6. 'variableName': 'appNotice',
  7. });
  8. if (res.success) {
  9. final String imageUrl = (res.data ?? {})['variableValue'] ?? '';
  10. if (imageUrl.isNotEmpty) {
  11. return showGeneralDialog(
  12. context: context,
  13. barrierDismissible: true,
  14. pageBuilder: (BuildContext buildContext, Animation<double> animation, Animation<double> secondaryAnimation) {
  15. return AppNotice(
  16. pics: ((res.data ?? {})['variableValue'] ?? '').split(','),
  17. );
  18. },
  19. barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
  20. barrierColor: Colors.black87,
  21. transitionDuration: const Duration(milliseconds: 300),
  22. );
  23. }
  24. }
  25. }
  26. class AppNotice extends StatefulWidget {
  27. final List<String> pics;
  28. const AppNotice({Key key, this.pics}) : super(key: key);
  29. @override
  30. State<StatefulWidget> createState() {
  31. return AppNoticeState();
  32. }
  33. }
  34. class AppNoticeState extends State<AppNotice> {
  35. final pageController = PageController(initialPage: 0);
  36. int currPage = 0;
  37. @override
  38. Widget build(BuildContext context) {
  39. widget.pics.forEach((f) {
  40. precacheImage(Image.network(f).image, context);
  41. });
  42. return Material(
  43. color: Colors.transparent,
  44. child: Column(
  45. mainAxisAlignment: MainAxisAlignment.center,
  46. mainAxisSize: MainAxisSize.min,
  47. children: <Widget>[
  48. SizedBox(
  49. width: double.infinity,
  50. height: (MediaQuery.of(context).size.width - 56) * 420 / 348,
  51. child: PageView(
  52. controller: pageController,
  53. onPageChanged: (page) {
  54. setState(() {
  55. currPage = page;
  56. });
  57. },
  58. children: widget.pics.map<Widget>((f) {
  59. return Container(
  60. height: (MediaQuery.of(context).size.width - 56) * 420 / 348,
  61. margin: EdgeInsets.only(left: 28, right: 28),
  62. child: SizedBox(
  63. child: ClipRRect(
  64. borderRadius: BorderRadius.circular(4),
  65. child: CachedNetworkImage(
  66. imageUrl: f,
  67. fit: BoxFit.cover,
  68. ),
  69. ),
  70. ),
  71. );
  72. }).toList(),
  73. ),
  74. ),
  75. Container(
  76. margin: EdgeInsets.only(top: 20),
  77. child: GestureDetector(
  78. child: Image.asset(currPage == widget.pics.length - 1 ? 'images/icon_guanbi.png' : 'images/icon_next_page.png'),
  79. onTap: () {
  80. if (currPage == widget.pics.length - 1) {
  81. Navigator.of(context).pop();
  82. } else {
  83. pageController.nextPage(duration: Duration(milliseconds: 500), curve: Curves.linearToEaseOut);
  84. }
  85. },
  86. ),
  87. )
  88. ],
  89. ),
  90. );
  91. }
  92. }