| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- import 'package:fast/constants.dart';
- import 'package:fast/model/model.dart';
- import 'package:fast/utils/api.dart';
- import 'package:fast/utils/global.dart';
- import 'package:fast/utils/http_utils.dart';
- import 'package:fast/utils/size_fit.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:get/get.dart';
- ///推送
- import 'package:jpush_flutter/jpush_flutter.dart';
- import 'component/fast.dart';
- class Controller extends GetxController {
- var topCover = 'assets/images/morning.png'.obs;
- changeCover(str) {
- topCover = str;
- }
- }
- class Home1Screen extends StatefulWidget {
- const Home1Screen({Key? key}) : super(key: key);
- @override
- _Home1ScreenState createState() => _Home1ScreenState();
- }
- class _Home1ScreenState extends State<Home1Screen> {
- var welcome = '早上好';
- String topCover = 'assets/images/morning.png';
- var isNight = false;
- var date = '';
- String debugLable = 'Unknown'; /*错误信息*/
- final JPush jpush = JPush(); /* 初始化极光插件*/
- @override
- void initState() {
- super.initState();
- loadData();
- setPush();
- getSystemTime();
- getFastStatus();
- getBalance();
- }
- void setPush() {
- jpush.setup(
- appKey: '7cf918ada725a9e9aecc8a17',
- production: false,
- debug: true,
- channel: '');
- jpush.applyPushAuthority(
- const NotificationSettingsIOS(sound: true, alert: true, badge: true));
- jpush.addEventHandler(
- onReceiveNotification: (Map<String, dynamic> message) async {
- // print(message);
- },
- onOpenNotification: (Map<String, dynamic> message) async {
- /// 点击通知栏消息,在此时通常可以做一些页面跳转等
- },
- );
- }
- Future getSystemTime() async {
- Map<String, dynamic> data = await HttpUtils.get(Api.serverTime);
- TimeBean timeBean = TimeBean.fromJson(data);
- // respo.
- var now = DateTime.now().millisecondsSinceEpoch ~/ 1000;
- Global().timeSeconds = timeBean.server_ts! - now;
- // var ts = respone.server_ts;
- }
- Future getFastStatus() async {
- Map<String, dynamic> data = await HttpUtils.get(Api.current);
- FastBean fastBean = FastBean.fromJson(data);
- if (fastBean.mode == null) {
- Global().firstStart = true;
- } else {}
- // var ts = respone.server_ts;
- }
- Future getBalance() async {
- Map<String, dynamic> data = await HttpUtils.get(Api.balance);
- Global().balance = data['rjv_balance'];
- }
- void loadData() {
- var now = DateTime.now();
- var hour = now.hour;
- var t = '';
- String img = 'assets/images/morning.png';
- if (hour < 6) {
- t = '凌晨好';
- img = 'assets/images/evening.png';
- isNight = true;
- } else if (hour < 9) {
- t = '早上好';
- } else if (hour < 12) {
- t = '上午好';
- img = 'assets/images/shangwu.png';
- } else if (hour < 14) {
- t = '中午好';
- img = 'assets/images/middle.png';
- } else if (hour < 17) {
- t = '下午好';
- img = 'assets/images/afternoon.png';
- } else if (hour < 19) {
- t = '傍晚好';
- img = 'assets/images/afternoon.png';
- } else {
- t = '晚上好';
- img = 'assets/images/evening.png';
- isNight = true;
- }
- setState(() {
- welcome = t;
- date = now.year.toString() +
- '-' +
- now.month.toString().padLeft(2, '0') +
- '-' +
- now.day.toString().padLeft(2, '0');
- topCover = img;
- isNight = isNight;
- });
- }
- @override
- Widget build(BuildContext context) {
- SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light);
- // final Controller c = Get.put(Controller());
- SizeFit.initialize(context);
- var size = MediaQuery.of(context).size;
- EdgeInsets safePadding = MediaQuery.of(context).padding;
- return Scaffold(
- body: Stack(
- children: [
- Container(
- decoration: BoxDecoration(
- image: DecorationImage(
- alignment: Alignment.topLeft, image: AssetImage(topCover))),
- ),
- Flex(
- direction: Axis.vertical,
- children: [
- Container(
- width: size.width,
- height: size.width * 360 / 750,
- padding: const EdgeInsets.fromLTRB(27, 64, 27, 0),
- alignment: Alignment.topLeft,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text('Leon',
- style: TextStyle(
- color: Colors.white,
- fontSize: 20.px,
- fontWeight: FontWeight.bold)),
- SizedBox(height: 10.px),
- Text(welcome + ',开始一天的好心情!',
- style: TextStyle(color: Colors.white, fontSize: 16.px)),
- SizedBox(height: 10.px),
- Text(date,
- style: TextStyle(
- color: const Color(0x99FFFFFF), fontSize: 12.px))
- ],
- )),
- Expanded(
- child: Container(
- alignment: Alignment.center,
- color: kBgColor,
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- const Fast(),
- // const Eat(),
- SizedBox(
- height: 20.px,
- ),
- Stack(
- alignment: AlignmentDirectional.topStart,
- children: [
- Opacity(
- opacity: 0.4,
- child: Container(
- width: 24.px,
- height: 24.px,
- margin:
- EdgeInsets.fromLTRB(3 * 12.px, 0, 0, 0),
- decoration: BoxDecoration(
- shape: BoxShape.circle,
- image: const DecorationImage(
- image: AssetImage(
- 'assets/images/shangwu.png'),
- fit: BoxFit.fitHeight),
- border: Border.all(
- color: const Color(0xFF000D26))),
- ),
- ),
- Opacity(
- opacity: 0.6,
- child: Container(
- width: 24.px,
- height: 24.px,
- margin:
- EdgeInsets.fromLTRB(2 * 12.px, 0, 0, 0),
- decoration: BoxDecoration(
- shape: BoxShape.circle,
- image: const DecorationImage(
- image: AssetImage(
- 'assets/images/shangwu.png'),
- fit: BoxFit.fitHeight),
- border: Border.all(
- color: const Color(0xFF000D26))),
- ),
- ),
- Opacity(
- opacity: 0.8,
- child: Container(
- width: 24.px,
- height: 24.px,
- margin: EdgeInsets.fromLTRB(12.px, 0, 0, 0),
- decoration: BoxDecoration(
- shape: BoxShape.circle,
- image: const DecorationImage(
- image: AssetImage(
- 'assets/images/shangwu.png'),
- fit: BoxFit.fitHeight),
- border: Border.all(
- color: const Color(0xFF000D26))),
- ),
- ),
- Container(
- width: 24.px,
- height: 24.px,
- decoration: BoxDecoration(
- shape: BoxShape.circle,
- image: const DecorationImage(
- image: AssetImage(
- 'assets/images/shangwu.png'),
- fit: BoxFit.fitHeight),
- border: Border.all(
- color: const Color(0xFF000D26))),
- ),
- Container(
- margin: EdgeInsets.fromLTRB(
- 12 * 3.px + 24.px + 8.px, 3.px, 0, 0),
- height: 16.px,
- child: Text(
- '346人完成6534次记录',
- style: TextStyle(
- color: const Color(0x66FFFFFF),
- fontSize: 14.px,
- ),
- ),
- )
- ],
- ),
- ],
- ))),
- Container(
- color: kBgColor,
- margin: const EdgeInsets.fromLTRB(0, 0, 0, 0),
- child: Container(
- width: double.infinity,
- height: 52,
- margin: const EdgeInsets.fromLTRB(14, 0, 14, 14),
- decoration: const BoxDecoration(
- color: Color(0xFF142133),
- borderRadius: BorderRadius.all(Radius.circular(26))),
- child: Flex(
- direction: Axis.horizontal,
- children: [
- Expanded(
- child: TextButton(
- onPressed: () => {},
- style: TextButton.styleFrom(
- padding: const EdgeInsets.all(0)),
- child: const Image(
- image:
- AssetImage('assets/images/tab_home_sel.png'),
- ))),
- Expanded(
- child: TextButton(
- onPressed: () => {},
- style: TextButton.styleFrom(
- padding: const EdgeInsets.all(0)),
- child: const Image(
- image: AssetImage(
- 'assets/images/tab_me.png',
- ),
- )))
- ],
- ),
- ),
- ),
- SizedBox(
- height: safePadding.bottom,
- )
- ],
- ),
- ],
- ));
- }
- }
|