123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424 |
- import 'package:flutter/material.dart';
- import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
- import 'package:get_it/get_it.dart';
- import 'package:nordic_dfu/nordic_dfu.dart';
- import 'package:provider/provider.dart';
- import 'package:sport/application.dart';
- import 'package:sport/bean/UpdateInfo.dart';
- import 'package:sport/bean/post_user.dart';
- import 'package:sport/pages/home/guide_page.dart';
- import 'package:sport/pages/social/user_friend_add_page.dart';
- import 'package:sport/pages/social/user_friend_page.dart';
- import 'package:sport/pages/social/user_post_page.dart';
- import 'package:sport/provider/bluetooth.dart';
- import 'package:sport/provider/message_model.dart';
- import 'package:sport/provider/user_model.dart';
- import 'package:sport/router/navigator_util.dart';
- import 'package:sport/router/routes.dart';
- import 'package:sport/services/api/inject_api.dart';
- import 'package:sport/services/api/resp.dart';
- import 'package:sport/utils/update_apk.dart';
- import 'package:sport/widgets/decoration.dart';
- import 'package:sport/widgets/dialog/search_device.dart';
- import 'package:sport/widgets/image.dart';
- import 'package:sport/widgets/list_tile.dart';
- import 'package:sport/widgets/space.dart';
- import 'package:sport/widgets/user_widget.dart';
- import 'package:umeng_common_sdk/umeng_common_sdk.dart';
- class MyPage extends StatefulWidget {
- @override
- _MyPageState createState() => _MyPageState();
- }
- class _MyPageState extends State<MyPage> with InjectApi {
- @override
- void initState() {
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- var rowPadding = EdgeInsets.symmetric(horizontal: 20.0);
- var textStyle = Theme.of(context).textTheme.subtitle1?.copyWith(fontSize: 16);
- return Scaffold(
- body: CustomScrollView(
- slivers: [
- SliverAppBar(
- floating: true,
- elevation: 0,
- expandedHeight: 120.0,
- flexibleSpace: FlexibleSpaceBar(
- collapseMode: CollapseMode.pin,
- background: Container(
- color: Colors.white,
- child: SafeArea(
- child: InkWell(
- child: Consumer<UserModel>(
- builder: (_, model, __) => Container(
- padding: const EdgeInsets.fromLTRB(20.0, 30.0, 20.0, 24.0),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Row(
- children: <Widget>[
- InkWell(
- onTap: () {
- NavigatorUtil.goSocialUserDetail(context, PostUser(id: model.user.id.toString(), name: model.user.name, avatar: model.user.avatar));
- },
- child: CircleAvatar(
- backgroundColor: Colors.black26,
- backgroundImage: userAvatarProvider(model.user.avatar),
- radius: 30,
- ),
- ),
- Space(
- width: 12,
- ),
- Column(
- mainAxisSize: MainAxisSize.min,
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Text(model.user.name, style: Theme.of(context).textTheme.headline1),
- Space(
- height: 10,
- ),
- Row(
- crossAxisAlignment: CrossAxisAlignment.baseline,
- textBaseline: TextBaseline.alphabetic,
- children: <Widget>[
- Image.asset("lib/assets/img/mine_icon_${model.user.gender == 1 ? "man" : "girl"}_gray.png"),
- Space(
- width: 4,
- ),
- Text(
- model.user.gender == 1 ? "男" : "女",
- style: Theme.of(context).textTheme.bodyText1,
- ),
- // if ((model.user.age ?? 0) != 0)
- // Padding(
- // padding: const EdgeInsets.only(left: 10.0),
- // child: Text(
- // "${model.user.age}岁",
- // style: TextStyle(color: Color(0xff999999), fontSize: 12),
- // ),
- // ),
- if ((model.user.weight ?? 0) != 0)
- Padding(
- padding: const EdgeInsets.only(left: 10.0),
- child: Text(
- "${model.user.weight}kg",
- style: Theme.of(context).textTheme.bodyText1,
- ),
- ),
- if (model.user.city != null)
- Padding(
- padding: const EdgeInsets.only(left: 10.0),
- child: Text(
- "${model.user.province}${model.user.province == model.user.city ? '' : model.user.city}",
- style: Theme.of(context).textTheme.bodyText1,
- ),
- ),
- ],
- ),
- ],
- ),
- ],
- ),
- Row(
- children: <Widget>[
- GestureDetector(
- onTap: (){
- NavigatorUtil.goPage(context, (context) => UserFriendAddPage());
- },
- child: Container(
- width: 22.0,
- height: 22.0,
- margin: const EdgeInsets.all(12.0),
- child: Image.asset("lib/assets/img/mine_icon_code.png"),
- ),
- ),
- arrowRight5(),
- SizedBox(
- width: 12.0,
- ),
- ],
- ),
- ],
- ),
- )),
- onTap: () => NavigatorUtil.go(context, Routes.userInfo),
- ),
- ),
- ),
- ),
- ),
- SliverToBoxAdapter(
- child: Container(
- padding: EdgeInsets.symmetric(horizontal: 12.0, vertical: 16.0),
- child: Column(
- children: [
- if (isDebugShoe)
- Container(
- child: ValueListenableBuilder<Map<String, int>>(
- valueListenable: GetIt.I<Bluetooth>().timeUseNotifier,
- builder: (context, data, _) {
- return Text(
- "连接用时(ms):${data.isNotEmpty ? data.values.reduce((previousValue, element) => previousValue + element) : 0} = $data",
- style: Theme.of(context).textTheme.bodyText1!.copyWith(color: Colors.green),
- );
- },
- ),
- padding: EdgeInsets.only(bottom: 12.0),
- ),
- Container(
- padding: EdgeInsets.symmetric(horizontal: 20, vertical: 8),
- decoration: circular(),
- child: ListTile(
- leading: Image.asset(
- "lib/assets/img/mine_image_shoe.png",
- height: 32.0,
- ),
- title: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text(
- "我的鞋子",
- style: Theme.of(context).textTheme.subtitle1!.copyWith(fontSize: 16.0),
- ),
- ValueListenableBuilder(
- valueListenable: GetIt.I<Bluetooth>().deviceNotifier,
- builder: (BuildContext context, DiscoveredDevice? d, Widget? child) {
- if (d == null)
- return Text(
- "未连接",
- style: Theme.of(context).textTheme.bodyText2,
- );
- return Text("已连接", style: Theme.of(context).textTheme.subtitle1!.copyWith(color: Color(0xff27D171)));
- },
- )
- ],
- ),
- trailing: arrowRight5(),
- contentPadding: EdgeInsets.zero,
- onTap: () {
- if (!GetIt.I<Bluetooth>().isConnected) {
- openSearchDeviceDialog(context);
- // ToastUtil.show("没连接设备!");
- return;
- }
- NavigatorUtil.go(context, Routes.deviceInfo);
- },
- ),
- ),
- Container(
- margin: EdgeInsets.only(top: 16.0),
- decoration: circular(),
- child: ListView(
- padding: EdgeInsets.symmetric(horizontal: 0, vertical: 0),
- physics: NeverScrollableScrollPhysics(),
- shrinkWrap: true,
- children: divideTiles(
- context: context,
- includeLast: false,
- tiles: [
- ListTile(
- title: Row(
- children: [
- Image.asset("lib/assets/img/mine_icon_level.png"),
- const SizedBox(
- width: 8,
- ),
- Text(
- "运动等级",
- style: textStyle,
- )
- ],
- ),
- contentPadding: rowPadding,
- trailing: arrowRight5(),
- onTap: () => NavigatorUtil.go(context, Routes.level),
- ),
- ListTile(
- title: Row(
- children: [
- Image.asset("lib/assets/img/mine_icon_record.png"),
- const SizedBox(
- width: 8,
- ),
- Text("运动记录", style: textStyle)
- ],
- ),
- contentPadding: rowPadding,
- trailing: arrowRight5(),
- onTap: () => NavigatorUtil.go(context, Routes.gamelistpage),
- ),
- if (openSocial())
- ListTile(
- title: Row(
- children: [
- Image.asset("lib/assets/img/mine_icon_invitation.png"),
- const SizedBox(
- width: 8,
- ),
- Text("社区帖子", style: textStyle)
- ],
- ),
- contentPadding: rowPadding,
- trailing: arrowRight5(),
- onTap: () {
- var userModel = Provider.of<UserModel>(context, listen: false);
- var user = userModel.user;
- var postUser = PostUser(id: "${user.id}", name: user.name, avatar: user.avatar);
- // NavigatorUtil.goSocialUserDetail(context,postUser);
- NavigatorUtil.goPage(context, (context) => UserPostPage(postUser));
- },
- ),
- ListTile(
- title: Row(
- children: [
- Image.asset("lib/assets/img/mine_icon_friend.png"),
- const SizedBox(
- width: 8,
- ),
- Text("我的好友", style: textStyle)
- ],
- ),
- contentPadding: rowPadding,
- trailing: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- ValueListenableBuilder(
- valueListenable: GetIt.I<MessageModel>().notifierFriendFansList,
- builder: (BuildContext context, int value, Widget? child) {
- int count = value;
- if (count == 0) return Container();
- return Positioned(
- right: -4,
- top: 4,
- child: Container(
- width: 8,
- height: 8,
- decoration: BoxDecoration(shape: BoxShape.circle, color: Colors.red),
- child: Text(
- "$value",
- style: Theme.of(context).textTheme.bodyText1?.copyWith(color: Colors.white, fontSize: 8),
- ),
- ),
- );
- },
- ),
- arrowRight5(),
- ],
- ),
- onTap: () => NavigatorUtil.goPage(context, (context) => UserFriendPage()),
- ),
- ],
- ).toList(),
- ),
- ),
- Container(
- margin: EdgeInsets.only(top: 16.0),
- decoration: circular(),
- child: ListView(
- padding: EdgeInsets.symmetric(horizontal: 0, vertical: 0),
- physics: NeverScrollableScrollPhysics(),
- shrinkWrap: true,
- children: divideTiles(
- context: context,
- includeLast: false,
- tiles: [
- ListTile(
- title: Row(
- children: [
- Image.asset("lib/assets/img/mine_icon_feedback.png"),
- const SizedBox(
- width: 8,
- ),
- Text("用户反馈", style: textStyle),
- ],
- ),
- contentPadding: rowPadding,
- trailing: arrowRight5(),
- onTap: () => NavigatorUtil.go(context, Routes.feedback),
- ),
- ListTile(
- title: Row(
- children: [
- Image.asset("lib/assets/img/mine_icon_novice.png"),
- const SizedBox(
- width: 8,
- ),
- Text("新手指引", style: textStyle),
- ],
- ),
- contentPadding: rowPadding,
- trailing: arrowRight5(),
- onTap: () {
- UmengCommonSdk.onEvent("my_novice", {});
- NavigatorUtil.goPage(context, (context) => GuidePage());
- },
- ),
- ],
- ).toList(),
- ),
- ),
- Container(
- margin: EdgeInsets.only(top: 16.0),
- decoration: circular(),
- child: ListView(
- padding: EdgeInsets.symmetric(horizontal: 0, vertical: 0),
- physics: NeverScrollableScrollPhysics(),
- shrinkWrap: true,
- children: divideTiles(
- context: context,
- includeLast: false,
- tiles: [
- ListTile(
- title: Row(
- children: [
- Image.asset("lib/assets/img/mine_icon_setup.png"),
- const SizedBox(
- width: 8,
- ),
- Text("设置", style: textStyle)
- ],
- ),
- contentPadding: rowPadding,
- trailing: Row(
- children: [
- FutureBuilder<RespData<UpdateInfo>>(
- builder: (_, data) {
- if (data.data?.data?.needUpdate == true) {
- return Container(
- width: 6,
- height: 6,
- margin: EdgeInsets.only(right: 8),
- decoration: BoxDecoration(shape: BoxShape.circle, color: Color(0xffFF5B1D)),
- );
- }
- return Container();
- },
- future: checkUpdate(),
- ),
- arrowRight5()
- ],
- mainAxisSize: MainAxisSize.min,
- ),
- onTap: () => NavigatorUtil.go(context, Routes.setting),
- ),
- ],
- ).toList(),
- ),
- ),
- ],
- )),
- ),
- ],
- ),
- );
- }
- }
|