123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- import 'dart:math';
- import 'package:cached_network_image/cached_network_image.dart';
- import 'package:dartin/dartin.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_easyrefresh/easy_refresh.dart';
- import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
- import 'package:provider/provider.dart';
- import 'package:sport/bean/post_user.dart';
- import 'package:sport/bean/user.dart';
- import 'package:sport/constant/ui.dart';
- import 'package:sport/pages/my/achievement_detail_page.dart';
- import 'package:sport/provider/user_model.dart';
- import 'package:sport/router/navigator_util.dart';
- import 'package:sport/services/api/inject_api.dart';
- import 'package:sport/services/api/login_api.dart';
- import 'package:sport/widgets/dialog/popupmenu.dart' as menu;
- import 'package:sport/widgets/image.dart';
- import 'package:sport/widgets/refresh_header.dart' as header;
- import 'package:sport/widgets/refresh_footer.dart';
- import 'package:sport/widgets/space.dart';
- Widget buildSocialUserWidget(BuildContext context, PostUser user, int createTime, int avatarWidth) {
- return user == null
- ? Container()
- : GestureDetector(
- onTap: () => NavigatorUtil.goSocialUserDetail(context, user),
- child: Row(
- children: <Widget>[
- Space(
- width: 12,
- ),
- CircleAvatar(backgroundImage: userAvatarProvider(user?.avatar), radius: avatarWidth / 2),
- Space(
- width: 8,
- ),
- Text(
- user?.name,
- style: Theme.of(context).textTheme.subtitle1.copyWith(fontWeight: FontWeight.w600),
- ),
- ],
- ));
- }
- Widget buildLabelWidget(BuildContext context, String title) {
- return Container(
- padding: EdgeInsets.fromLTRB(ui_padding, 10.0, ui_padding, 10.0),
- child: Text(
- title,
- style: Theme.of(context).textTheme.headline1.copyWith(fontSize: 16.0,),
- ));
- }
- Widget gameTag(BuildContext context, String name) {
- return Container(
- decoration: BoxDecoration(
- borderRadius: BorderRadius.all(Radius.circular(50)),
- border: Border.all(
- color: Theme.of(context).accentColor,
- width: 1,
- ),
- ),
- padding: EdgeInsets.fromLTRB(8, 0, 8, 1),
- child: Text(
- name,
- style: Theme.of(context).textTheme.bodyText1.copyWith(color: Theme.of(context).accentColor),
- strutStyle: fixedLine,
- ),
- );
- }
- Widget achievementGroupWidget(List<Achievement> achievements) {
- return achievements == null || achievements.isEmpty
- ? Center(child: Container(child: Padding(padding: const EdgeInsets.all(24.0), child: Text("还未获得成就"))))
- : StaggeredGridView.countBuilder(
- padding: EdgeInsets.zero,
- shrinkWrap: true,
- physics: NeverScrollableScrollPhysics(),
- crossAxisCount: 4,
- itemCount: min(4, achievements.length),
- itemBuilder: (BuildContext context, int index) => achievementWidget(context, achievements[index]),
- crossAxisSpacing: 12.0,
- staggeredTileBuilder: (int index) => StaggeredTile.fit(1),
- );
- }
- Widget achievementWidget(BuildContext context, Achievement item, {double w = 70, bool replace = false, bool isRadius = false, bool jump = true,showCount=false}) => InkWell(
- onTap: () async {
- // 不能看别人的成就...
- if(item.userId != null && Provider.of<UserModel>(context, listen: false).user.id != item.userId)
- return;
- // if (jump == true) NavigatorUtil.goAchievementDetails(context, id: item.id, userId: item.userId ?? 0, replace: replace);
- if(jump == true) {
- List<Achievement> relateAchievements = (await inject<LoginApi>().getAchieveDetailInfo(item.id)).data.relateAchievements;
- showSharePopup(context,relateAchievements,item.id);
- }
- },
- child: Stack(
- children: <Widget>[
- Column(
- children: <Widget>[
- isRadius
- ? CircleAvatar(backgroundImage: CachedNetworkImageProvider(item.logo ?? ""), radius: w / 2)
- : item?.createdAt == ""
- ? ColorFiltered(
- colorFilter: ColorFilter.mode(Color(0xffF1F1F1), BlendMode.color),
- child: CachedNetworkImage(width: w, height: w, imageUrl: item.logo ?? ""),
- )
- : Container(
- width: w,
- height: w,
- child: CachedNetworkImage(imageUrl: item.logo ?? ""),
- ),
- Space(
- height: 5,
- ),
- Text(
- item.seriesName != null ? item.seriesName : item.name,
- // style: Theme.of(context).textTheme.subtitle1.copyWith(fontSize: w < 80 ? 12 : 14),
- style:Theme.of(context).textTheme.subtitle1.copyWith(fontSize: 12)
- )
- ],
- ),
- showCount ? Positioned(
- top: 0,
- right: 10.0,
- child: Container(
- alignment: Alignment.center,
- width: 32.0,height: 21.0,
- decoration: BoxDecoration(
- image: DecorationImage(
- image: AssetImage("lib/assets/img/bg_achievement_number.png"),
- fit: BoxFit.cover,
- )
- ),
- child: Text("${item.seriesCount}枚",style:TextStyle(fontSize: 12.0,color:Colors.white),strutStyle: StrutStyle(forceStrutHeight: true, height: 0.8),),
- )
- ):Container()
- ],
- ));
- Widget sportBeEquivalentTo(BuildContext context, int consume, {bool highlight = false}) => Padding(
- padding: EdgeInsets.all(10.0),
- child: Text(
- "消耗了 ${(consume / 50).round()} 块小饼干",
- style: Theme.of(context).textTheme.subtitle1,
- ),
- );
- // Row(
- // mainAxisAlignment: MainAxisAlignment.spaceAround,
- // children: <Widget>[
- // Column(
- // children: <Widget>[
- // Image.asset("lib/assets/img/gamedetail_image_walk.png"),
- // Space(
- // height: 8,
- // ),
- // RichText(
- // text: TextSpan(children: <InlineSpan>[
- // TextSpan(text: '步行', style: Theme.of(context).textTheme.bodyText1),
- // TextSpan(
- // text: '${(consume / 3 * 90).floor()}',
- // style: highlight
- // ? Theme.of(context).textTheme.bodyText1.copyWith(color: Theme.of(context).accentColor)
- // : Theme.of(context).textTheme.bodyText1),
- // TextSpan(text: '步', style: Theme.of(context).textTheme.bodyText1),
- // ]),
- // )
- // ],
- // ),
- // Column(
- // children: <Widget>[
- // Image.asset("lib/assets/img/gamedetail_image_run.png"),
- // Space(
- // height: 8,
- // ),
- // RichText(
- // text: TextSpan(children: <InlineSpan>[
- // TextSpan(text: '跑步', style: Theme.of(context).textTheme.bodyText1),
- // TextSpan(
- // text: '${(consume / 60 / 1.036).toStringAsFixed(1)}',
- // style: highlight
- // ? Theme.of(context).textTheme.bodyText1.copyWith(color: Theme.of(context).accentColor)
- // : Theme.of(context).textTheme.bodyText1),
- // TextSpan(text: '公里', style: Theme.of(context).textTheme.bodyText1),
- // ]),
- // )
- // ],
- // ),
- // Column(
- // children: <Widget>[
- // Image.asset("lib/assets/img/gamedetail_image_riding.png"),
- // Space(
- // height: 8,
- // ),
- // RichText(
- // text: TextSpan(children: <InlineSpan>[
- // TextSpan(text: '单车', style: Theme.of(context).textTheme.bodyText1),
- // TextSpan(
- // text: '${(consume / 60 / 0.6142).toStringAsFixed(1)}',
- // style: highlight
- // ? Theme.of(context).textTheme.bodyText1.copyWith(color: Theme.of(context).accentColor)
- // : Theme.of(context).textTheme.bodyText1),
- // TextSpan(text: '公里', style: Theme.of(context).textTheme.bodyText1),
- // ]),
- // )
- // ],
- // ),
- // ],
- // );
- const REFRESH_INFO_COLOR = Color(0xff999999);
- header.ClassicalHeader buildClassicalHeader(
- {double extent = 80.0,
- double triggerDistance = 90.0,
- Color infoColor = REFRESH_INFO_COLOR,
- Color textColor = REFRESH_INFO_COLOR,
- Color bgColor = Colors.transparent,
- }) {
- return header.ClassicalHeader(
- extent: extent,
- triggerDistance: triggerDistance,
- showInfo: false,
- refreshText: '下拉刷新',
- refreshFailedText: '刷新失败',
- refreshedText: '刷新完成',
- refreshingText: '正在刷新...',
- refreshReadyText: '释放刷新',
- infoColor: infoColor,
- bgColor: bgColor,
- textColor: infoColor,
- );
- }
- Footer buildClassicalFooter() {
- return CustomClassicalFooter(
- showInfo: false,
- loadedText: '加载完成',
- loadReadyText: '释放加载',
- loadFailedText: '加载失败',
- loadText: '拉动加载',
- loadingText: '正在加载...',
- noMoreText: "没有更多了~",
- infoColor: Color(0xff999999));
- }
- PopupMenuEntry menuDivider() => menu.PopupMenuItem(
- height: 1,
- child: Divider(
- height: 1,
- ),
- );
- PopupMenuEntry menuItem(String value, String icon, String text) => menu.PopupMenuItem(
- value: value,
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: <Widget>[
- Image.asset(
- "lib/assets/img/$icon",
- width: 24,
- ),
- SizedBox(
- width: 4,
- ),
- Text(
- text,
- )
- ],
- ),
- );
- PopupMenuEntry menuItemCenter(dynamic value, String text) => menu.PopupMenuItem(
- value: value,
- child: Center(
- child: Text(
- text,
- )),
- );
- PopupMenuEntry menuItemSelected(dynamic value, String text, bool select) => menu.PopupMenuItem(
- value: value,
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: <Widget>[
- Container(
- alignment: AlignmentDirectional.centerStart,
- constraints: BoxConstraints(minWidth: 60),
- padding: const EdgeInsets.symmetric(horizontal: 8.0),
- child: select
- ? Text(
- text,
- style: TextStyle(color: Color(0xffFFC400)),
- )
- : Text(
- text,
- ),
- ),
- if (select)
- Image.asset(
- "lib/assets/img/pop_icon_selected.png",
- width: 24,
- ),
- ],
- ));
- List<PopupMenuEntry> divideMenus(Iterable<PopupMenuEntry> tiles) {
- assert(tiles != null);
- final Iterator<PopupMenuEntry> iterator = tiles.iterator;
- final PopupMenuEntry divider = menuDivider();
- final List<PopupMenuEntry> list = [];
- while (iterator.moveNext()) {
- list.add(iterator.current);
- list.add(divider);
- }
- if (list.length > 1) list.removeAt(list.length - 1);
- return list;
- }
- const StrutStyle fixedLine = StrutStyle(forceStrutHeight: true);
|