Hibok
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.
 
 
 
 
 
 

177 lines
5.2 KiB

  1. import 'package:chat/generated/i18n.dart';
  2. import 'package:chat/utils/screen.dart';
  3. import 'package:chat/utils/sp_utils.dart';
  4. import 'package:flutter/cupertino.dart';
  5. import 'package:flutter/material.dart';
  6. import '../data/constants.dart';
  7. import 'IndexPage.dart';
  8. class SplashPage extends StatefulWidget {
  9. @override
  10. State<StatefulWidget> createState() {
  11. return SplashPageState();
  12. }
  13. }
  14. class SplashBean {
  15. String icon;
  16. String title;
  17. String content;
  18. Color titleColor;
  19. SplashBean(this.icon, this.title, this.content, this.titleColor);
  20. }
  21. class SplashPageState extends State<SplashPage> {
  22. List<SplashBean> list = [];
  23. int currentIndex = 0;
  24. PageController pageController;
  25. @override
  26. void initState() {
  27. super.initState();
  28. list.add(SplashBean(
  29. 'assets/images/img_splash_1.png',
  30. I18n.of(Constants.getCurrentContext()).splash_tips1,
  31. I18n.of(Constants.getCurrentContext()).splash_tips_content1,
  32. Color(0xffEC527D)));
  33. list.add(SplashBean(
  34. 'assets/images/img_splash_2.png',
  35. I18n.of(Constants.getCurrentContext()).splash_tips2,
  36. I18n.of(Constants.getCurrentContext()).splash_tips_content2,
  37. Color(0xffB439EB)));
  38. list.add(SplashBean(
  39. 'assets/images/img_splash_3.png',
  40. I18n.of(Constants.getCurrentContext()).splash_tips3,
  41. I18n.of(Constants.getCurrentContext()).splash_tips_content3,
  42. Color(0xff2B79F7)));
  43. pageController = PageController(
  44. initialPage: 0,
  45. );
  46. }
  47. @override
  48. Widget build(BuildContext context) {
  49. return Scaffold(
  50. body: Container(
  51. color: Colors.white,
  52. child: SafeArea(
  53. child: Container(
  54. color: Colors.white,
  55. child: Stack(
  56. children: <Widget>[
  57. PageView.builder(
  58. controller: pageController,
  59. itemBuilder: _buildItem,
  60. itemCount: list.length,
  61. onPageChanged: (int index) {
  62. setState(() {
  63. currentIndex = index;
  64. });
  65. },
  66. ),
  67. Container(
  68. child: Column(
  69. children: <Widget>[
  70. Expanded(child: Container()),
  71. currentIndex != 2 ? getIndicator() : Container(),
  72. currentIndex == 2
  73. ? InkWell(
  74. onTap: () async {
  75. await SPUtils.saveBool(
  76. Constants.Splash_OPENED, true);
  77. Navigator.of(context).push(
  78. MaterialPageRoute(
  79. builder: (_) => IndexPage(),
  80. ),
  81. );
  82. },
  83. child: Padding(
  84. padding: EdgeInsets.only(bottom: 40),
  85. child: Container(
  86. padding: EdgeInsets.only(
  87. left: 16, right: 16, top: 5, bottom: 5),
  88. decoration: BoxDecoration(
  89. border: Border.all(
  90. color: Color(0xff2B79F7), width: 1),
  91. borderRadius: BorderRadius.circular(16)),
  92. child: Text(
  93. I18n.of(context).splash_go,
  94. textScaleFactor: 1.0,
  95. style: TextStyle(
  96. fontSize: 18, color: Color(0xff2B79F7)),
  97. ),
  98. ),
  99. ),
  100. )
  101. : Container(),
  102. ],
  103. ),
  104. )
  105. ],
  106. ),
  107. )),
  108. ),
  109. );
  110. }
  111. Widget getIndicator() {
  112. List<Widget> pointList = [];
  113. for (int k = 0; k < list.length; k++) {
  114. pointList.add(Padding(
  115. padding: EdgeInsets.only(left: 6, right: 6),
  116. child: ClipOval(
  117. child: Container(
  118. color: k == currentIndex ? Color(0xff2B79F7) : Color(0xffBFBEBE),
  119. width: 10,
  120. height: 10,
  121. ),
  122. ),
  123. ));
  124. }
  125. return Padding(
  126. padding: EdgeInsets.only(bottom: 40),
  127. child: Container(
  128. width: Screen.width,
  129. child: Row(
  130. mainAxisAlignment: MainAxisAlignment.center,
  131. children: pointList,
  132. ),
  133. ),
  134. );
  135. }
  136. Widget _buildItem(BuildContext context, int index) {
  137. SplashBean data = list[index];
  138. return Container(
  139. child: Column(
  140. children: <Widget>[
  141. Padding(
  142. padding: EdgeInsets.only(top: 30, bottom: 40),
  143. child: Image.asset(
  144. data.icon,
  145. height: 400,
  146. ),
  147. ),
  148. Text(
  149. data.title,
  150. textScaleFactor: 1.0,
  151. style: TextStyle(color: data.titleColor, fontSize: 30),
  152. ),
  153. SizedBox(
  154. height: 6,
  155. ),
  156. Text(data.content,
  157. textScaleFactor: 1.0,
  158. style: TextStyle(color: Color(0xff999999), fontSize: 15)),
  159. ],
  160. ),
  161. );
  162. }
  163. }