home1.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. import 'package:fast/constants.dart';
  2. import 'package:fast/model/model.dart';
  3. import 'package:fast/utils/api.dart';
  4. import 'package:fast/utils/global.dart';
  5. import 'package:fast/utils/http_utils.dart';
  6. import 'package:fast/utils/size_fit.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:flutter/services.dart';
  9. import 'package:get/get.dart';
  10. ///推送
  11. import 'package:jpush_flutter/jpush_flutter.dart';
  12. import 'component/fast.dart';
  13. class Controller extends GetxController {
  14. var topCover = 'assets/images/morning.png'.obs;
  15. changeCover(str) {
  16. topCover = str;
  17. }
  18. }
  19. class Home1Screen extends StatefulWidget {
  20. const Home1Screen({Key? key}) : super(key: key);
  21. @override
  22. _Home1ScreenState createState() => _Home1ScreenState();
  23. }
  24. class _Home1ScreenState extends State<Home1Screen> {
  25. var welcome = '早上好';
  26. String topCover = 'assets/images/morning.png';
  27. var isNight = false;
  28. var date = '';
  29. String debugLable = 'Unknown'; /*错误信息*/
  30. final JPush jpush = JPush(); /* 初始化极光插件*/
  31. @override
  32. void initState() {
  33. super.initState();
  34. loadData();
  35. setPush();
  36. getSystemTime();
  37. getFastStatus();
  38. getBalance();
  39. }
  40. void setPush() {
  41. jpush.setup(
  42. appKey: '7cf918ada725a9e9aecc8a17',
  43. production: false,
  44. debug: true,
  45. channel: '');
  46. jpush.applyPushAuthority(
  47. const NotificationSettingsIOS(sound: true, alert: true, badge: true));
  48. jpush.addEventHandler(
  49. onReceiveNotification: (Map<String, dynamic> message) async {
  50. // print(message);
  51. },
  52. onOpenNotification: (Map<String, dynamic> message) async {
  53. /// 点击通知栏消息,在此时通常可以做一些页面跳转等
  54. },
  55. );
  56. }
  57. Future getSystemTime() async {
  58. Map<String, dynamic> data = await HttpUtils.get(Api.serverTime);
  59. TimeBean timeBean = TimeBean.fromJson(data);
  60. // respo.
  61. var now = DateTime.now().millisecondsSinceEpoch ~/ 1000;
  62. Global().timeSeconds = timeBean.server_ts! - now;
  63. // var ts = respone.server_ts;
  64. }
  65. Future getFastStatus() async {
  66. Map<String, dynamic> data = await HttpUtils.get(Api.current);
  67. FastBean fastBean = FastBean.fromJson(data);
  68. if (fastBean.mode == null) {
  69. Global().firstStart = true;
  70. } else {}
  71. // var ts = respone.server_ts;
  72. }
  73. Future getBalance() async {
  74. Map<String, dynamic> data = await HttpUtils.get(Api.balance);
  75. Global().balance = data['rjv_balance'];
  76. }
  77. void loadData() {
  78. var now = DateTime.now();
  79. var hour = now.hour;
  80. var t = '';
  81. String img = 'assets/images/morning.png';
  82. if (hour < 6) {
  83. t = '凌晨好';
  84. img = 'assets/images/evening.png';
  85. isNight = true;
  86. } else if (hour < 9) {
  87. t = '早上好';
  88. } else if (hour < 12) {
  89. t = '上午好';
  90. img = 'assets/images/shangwu.png';
  91. } else if (hour < 14) {
  92. t = '中午好';
  93. img = 'assets/images/middle.png';
  94. } else if (hour < 17) {
  95. t = '下午好';
  96. img = 'assets/images/afternoon.png';
  97. } else if (hour < 19) {
  98. t = '傍晚好';
  99. img = 'assets/images/afternoon.png';
  100. } else {
  101. t = '晚上好';
  102. img = 'assets/images/evening.png';
  103. isNight = true;
  104. }
  105. setState(() {
  106. welcome = t;
  107. date = now.year.toString() +
  108. '-' +
  109. now.month.toString().padLeft(2, '0') +
  110. '-' +
  111. now.day.toString().padLeft(2, '0');
  112. topCover = img;
  113. isNight = isNight;
  114. });
  115. }
  116. @override
  117. Widget build(BuildContext context) {
  118. SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light);
  119. // final Controller c = Get.put(Controller());
  120. SizeFit.initialize(context);
  121. var size = MediaQuery.of(context).size;
  122. EdgeInsets safePadding = MediaQuery.of(context).padding;
  123. return Scaffold(
  124. body: Stack(
  125. children: [
  126. Container(
  127. decoration: BoxDecoration(
  128. image: DecorationImage(
  129. alignment: Alignment.topLeft, image: AssetImage(topCover))),
  130. ),
  131. Flex(
  132. direction: Axis.vertical,
  133. children: [
  134. Container(
  135. width: size.width,
  136. height: size.width * 360 / 750,
  137. padding: const EdgeInsets.fromLTRB(27, 64, 27, 0),
  138. alignment: Alignment.topLeft,
  139. child: Column(
  140. crossAxisAlignment: CrossAxisAlignment.start,
  141. children: [
  142. Text('Leon',
  143. style: TextStyle(
  144. color: Colors.white,
  145. fontSize: 20.px,
  146. fontWeight: FontWeight.bold)),
  147. SizedBox(height: 10.px),
  148. Text(welcome + ',开始一天的好心情!',
  149. style: TextStyle(color: Colors.white, fontSize: 16.px)),
  150. SizedBox(height: 10.px),
  151. Text(date,
  152. style: TextStyle(
  153. color: const Color(0x99FFFFFF), fontSize: 12.px))
  154. ],
  155. )),
  156. Expanded(
  157. child: Container(
  158. alignment: Alignment.center,
  159. color: kBgColor,
  160. child: Column(
  161. mainAxisSize: MainAxisSize.min,
  162. children: [
  163. const Fast(),
  164. // const Eat(),
  165. SizedBox(
  166. height: 20.px,
  167. ),
  168. Stack(
  169. alignment: AlignmentDirectional.topStart,
  170. children: [
  171. Opacity(
  172. opacity: 0.4,
  173. child: Container(
  174. width: 24.px,
  175. height: 24.px,
  176. margin:
  177. EdgeInsets.fromLTRB(3 * 12.px, 0, 0, 0),
  178. decoration: BoxDecoration(
  179. shape: BoxShape.circle,
  180. image: const DecorationImage(
  181. image: AssetImage(
  182. 'assets/images/shangwu.png'),
  183. fit: BoxFit.fitHeight),
  184. border: Border.all(
  185. color: const Color(0xFF000D26))),
  186. ),
  187. ),
  188. Opacity(
  189. opacity: 0.6,
  190. child: Container(
  191. width: 24.px,
  192. height: 24.px,
  193. margin:
  194. EdgeInsets.fromLTRB(2 * 12.px, 0, 0, 0),
  195. decoration: BoxDecoration(
  196. shape: BoxShape.circle,
  197. image: const DecorationImage(
  198. image: AssetImage(
  199. 'assets/images/shangwu.png'),
  200. fit: BoxFit.fitHeight),
  201. border: Border.all(
  202. color: const Color(0xFF000D26))),
  203. ),
  204. ),
  205. Opacity(
  206. opacity: 0.8,
  207. child: Container(
  208. width: 24.px,
  209. height: 24.px,
  210. margin: EdgeInsets.fromLTRB(12.px, 0, 0, 0),
  211. decoration: BoxDecoration(
  212. shape: BoxShape.circle,
  213. image: const DecorationImage(
  214. image: AssetImage(
  215. 'assets/images/shangwu.png'),
  216. fit: BoxFit.fitHeight),
  217. border: Border.all(
  218. color: const Color(0xFF000D26))),
  219. ),
  220. ),
  221. Container(
  222. width: 24.px,
  223. height: 24.px,
  224. decoration: BoxDecoration(
  225. shape: BoxShape.circle,
  226. image: const DecorationImage(
  227. image: AssetImage(
  228. 'assets/images/shangwu.png'),
  229. fit: BoxFit.fitHeight),
  230. border: Border.all(
  231. color: const Color(0xFF000D26))),
  232. ),
  233. Container(
  234. margin: EdgeInsets.fromLTRB(
  235. 12 * 3.px + 24.px + 8.px, 3.px, 0, 0),
  236. height: 16.px,
  237. child: Text(
  238. '346人完成6534次记录',
  239. style: TextStyle(
  240. color: const Color(0x66FFFFFF),
  241. fontSize: 14.px,
  242. ),
  243. ),
  244. )
  245. ],
  246. ),
  247. ],
  248. ))),
  249. Container(
  250. color: kBgColor,
  251. margin: const EdgeInsets.fromLTRB(0, 0, 0, 0),
  252. child: Container(
  253. width: double.infinity,
  254. height: 52,
  255. margin: const EdgeInsets.fromLTRB(14, 0, 14, 14),
  256. decoration: const BoxDecoration(
  257. color: Color(0xFF142133),
  258. borderRadius: BorderRadius.all(Radius.circular(26))),
  259. child: Flex(
  260. direction: Axis.horizontal,
  261. children: [
  262. Expanded(
  263. child: TextButton(
  264. onPressed: () => {},
  265. style: TextButton.styleFrom(
  266. padding: const EdgeInsets.all(0)),
  267. child: const Image(
  268. image:
  269. AssetImage('assets/images/tab_home_sel.png'),
  270. ))),
  271. Expanded(
  272. child: TextButton(
  273. onPressed: () => {},
  274. style: TextButton.styleFrom(
  275. padding: const EdgeInsets.all(0)),
  276. child: const Image(
  277. image: AssetImage(
  278. 'assets/images/tab_me.png',
  279. ),
  280. )))
  281. ],
  282. ),
  283. ),
  284. ),
  285. SizedBox(
  286. height: safePadding.bottom,
  287. )
  288. ],
  289. ),
  290. ],
  291. ));
  292. }
  293. }