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:fast/view/calendar.dart'; import 'package:fast/view/component/header.dart'; import 'package:fast/view/recharge.dart'; import 'package:fast/view/setting.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'dart:convert' as convert; import 'package:shared_preferences/shared_preferences.dart'; import 'balance_history.dart'; class MePage extends StatefulWidget { const MePage({Key? key}) : super(key: key); @override State createState() => _MePageState(); } class _MePageState extends State with RouteAware { late UserBean userBean; @override void initState() { userBean = Global().userBean!; super.initState(); } @override void didChangeDependencies() { super.didChangeDependencies(); Global().routeObserver!.subscribe(this, ModalRoute.of(context)!); } @override void didPopNext() { getUserInfo(); super.didPopNext(); } Future getUserInfo() async { if (mounted) { final prefs = await SharedPreferences.getInstance(); String? temp = prefs.getString('userInfo'); if (temp != null) { Map data = convert.jsonDecode(temp); UserBean bean = UserBean.fromJson(data); setState(() { userBean = bean; }); } } } @override Widget build(BuildContext context) { SizeFit.initialize(context); var size = MediaQuery.of(context).size; bool isNight = false; DateTime now = DateTime.now(); if (now.hour >= 18 || now.hour < 6) { isNight = true; } return SizedBox( width: double.infinity, height: double.infinity, child: Column( children: [ Stack( children: [ Header( isIndexPage: false, ), Container( padding: EdgeInsets.fromLTRB(24.px, size.height<=667?50.px:68.px, 24.px, 0), height: size.height<=667?162.px:180.px, child: Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ ClipOval( child: Image.network( userBean.avatar!, width: 64.px, height: 64.px, fit: BoxFit.cover, ), ), SizedBox( width: 10.px, ), Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( userBean.nickname!, textAlign: TextAlign.left, style: TextStyle( color: isNight ? Colors.white : const Color(0xFF000D1F), fontSize: 20.px, fontWeight: FontWeight.bold), ), SizedBox( height: 6.px, ), Row( children: [ Container( height: 24.px, padding: EdgeInsets.only( left: 9.px, right: 9.px), decoration: BoxDecoration( borderRadius: BorderRadius.all( Radius.circular(12.px)), border: Border.all( color: const Color(0x80FFFFFF), width: 1.px), color: const Color(0x33000D1F)), child: Row( children: [ Text( '逆龄石', style: TextStyle( color: Colors.white, fontSize: 12.px), ), SizedBox( width: 2.px, ), Image.asset( 'assets/images/stone.png', width: 16.px, height: 16.px, ), SizedBox( width: 2.px, ), Text( '×${userBean.rjvBalance}', style: TextStyle( color: kThemeColor, fontSize: 14.px, fontFamily: 'Exo2', fontWeight: FontWeight.w600), ), Container( width: 1.px, height: 14.px, margin: EdgeInsets.only(left: 6.px,right: 6.px), color: const Color(0x80FFFFFF), ), GestureDetector(onTap: (){ Get.to(() => const Recharge()); }, child: Text('去充值',style: TextStyle(color: Colors.white,fontSize: 10.px),), ) ], ), ), GestureDetector( onTap: () { Get.to(() => const Setting()); }, child: Container( width: 24.px, height: 24.px, margin: EdgeInsets.only(left: 10.px), alignment: Alignment.center, child: Image.asset( 'assets/images/setting.png', width: 16.px, height: 16.px, ), decoration: BoxDecoration( color: const Color(0x33000D1F), borderRadius: BorderRadius.all( Radius.circular(12.px)), border: Border.all( color: const Color(0x80FFFFFF), width: 1.px)), ), ) ], ) ]) ], ), ) ], ), const Expanded(child: Calendar()) ], ), ); } }