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.
 
 
 
 
 
 

193 line
5.7 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_4.png',
  35. I18n.of(Constants.getCurrentContext()).travel_butler,
  36. I18n.of(Constants.getCurrentContext()).splash_tips_content5,
  37. Color(0xFF2B79F7)));
  38. list.add(SplashBean(
  39. 'assets/images/img_splash_5.png',
  40. I18n.of(Constants.getCurrentContext()).translation_butler,
  41. I18n.of(Constants.getCurrentContext()).splash_tips_content4,
  42. Color(0xFFBE58FF)));
  43. list.add(SplashBean(
  44. 'assets/images/img_splash_2.png',
  45. I18n.of(Constants.getCurrentContext()).splash_tips2,
  46. I18n.of(Constants.getCurrentContext()).splash_tips_content2,
  47. Color(0xffB439EB)));
  48. list.add(SplashBean(
  49. 'assets/images/img_splash_3.png',
  50. I18n.of(Constants.getCurrentContext()).splash_tips3,
  51. I18n.of(Constants.getCurrentContext()).splash_tips_content3,
  52. Color(0xff2B79F7)));
  53. pageController = PageController(
  54. initialPage: 0,
  55. );
  56. }
  57. @override
  58. Widget build(BuildContext context) {
  59. return Scaffold(
  60. body: Container(
  61. color: Colors.white,
  62. child: SafeArea(
  63. child: Container(
  64. color: Colors.white,
  65. child: Stack(
  66. children: <Widget>[
  67. PageView.builder(
  68. controller: pageController,
  69. itemBuilder: _buildItem,
  70. itemCount: list.length,
  71. onPageChanged: (int index) {
  72. setState(() {
  73. currentIndex = index;
  74. });
  75. },
  76. ),
  77. Container(
  78. child: Column(
  79. children: <Widget>[
  80. Expanded(child: Container()),
  81. currentIndex != 3 ? getIndicator() : Container(),
  82. currentIndex == 3
  83. ? InkWell(
  84. onTap: () async {
  85. await SPUtils.saveBool(
  86. Constants.Splash_OPENED, true);
  87. Navigator.of(context).push(
  88. MaterialPageRoute(
  89. builder: (_) => IndexPage(),
  90. ),
  91. );
  92. },
  93. child: Padding(
  94. padding: EdgeInsets.only(bottom: 40),
  95. child: Container(
  96. padding: EdgeInsets.only(
  97. left: 16, right: 16, top: 5, bottom: 5),
  98. decoration: BoxDecoration(
  99. border: Border.all(
  100. color: Color(0xff2B79F7), width: 1),
  101. borderRadius: BorderRadius.circular(16)),
  102. child: Text(
  103. I18n.of(context).splash_go,
  104. textScaleFactor: 1.0,
  105. style: TextStyle(
  106. fontSize: 18, color: Color(0xff2B79F7)),
  107. ),
  108. ),
  109. ),
  110. )
  111. : Container(),
  112. ],
  113. ),
  114. )
  115. ],
  116. ),
  117. )),
  118. ),
  119. );
  120. }
  121. Widget getIndicator() {
  122. List<Widget> pointList = [];
  123. for (int k = 0; k < list.length; k++) {
  124. pointList.add(Padding(
  125. padding: EdgeInsets.only(left: 6, right: 6),
  126. child: ClipOval(
  127. child: Container(
  128. color: k == currentIndex ? Color(0xff2B79F7) : Color(0xffBFBEBE),
  129. width: 10,
  130. height: 10,
  131. ),
  132. ),
  133. ));
  134. }
  135. return Padding(
  136. padding: EdgeInsets.only(bottom: 40),
  137. child: Container(
  138. width: Screen.width,
  139. child: Row(
  140. mainAxisAlignment: MainAxisAlignment.center,
  141. children: pointList,
  142. ),
  143. ),
  144. );
  145. }
  146. Widget _buildItem(BuildContext context, int index) {
  147. SplashBean data = list[index];
  148. return Container(
  149. child: Column(
  150. children: <Widget>[
  151. Padding(
  152. padding: EdgeInsets.only(top: 30, bottom: 40),
  153. child: Image.asset(
  154. data.icon,
  155. height: 400,
  156. ),
  157. ),
  158. Text(
  159. data.title,
  160. textScaleFactor: 1.0,
  161. textAlign: TextAlign.center,
  162. style: TextStyle(color: data.titleColor, fontSize: 30),
  163. ),
  164. SizedBox(
  165. height: 6,
  166. ),
  167. Text(data.content,
  168. textScaleFactor: 1.0,
  169. style: TextStyle(color: Color(0xff999999), fontSize: 15)),
  170. ],
  171. ),
  172. );
  173. }
  174. }