diff --git a/lib/address/address_map_page.dart b/lib/address/address_map_page.dart index 2a96c872..1f75590f 100644 --- a/lib/address/address_map_page.dart +++ b/lib/address/address_map_page.dart @@ -15,6 +15,7 @@ import 'package:flutter_baidu_mapapi_utils/flutter_baidu_mapapi_utils.dart'; import 'package:flutter_bmflocation/bdmap_location_flutter_plugin.dart'; import 'package:flutter_bmflocation/flutter_baidu_location_android_option.dart'; import 'package:flutter_bmflocation/flutter_baidu_location_ios_option.dart'; +import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/retrofit/data/address.dart'; @@ -199,10 +200,10 @@ class _AddressMapPage extends State { if (await Permission.location.isPermanentlyDenied) { requestDialog(); } else if (await Permission.location.isGranted) { - SmartDialog.showLoading(msg: S.of(context).zhengzaijiazai, animationDurationTemp: Duration(seconds: 1)); + EasyLoading.show(status: S.of(context).zhengzaijiazai); aMapFlutterLocation.startLocation(); Future.delayed(Duration(seconds: 6), () { - SmartDialog.dismiss(); + EasyLoading.dismiss(); }); } else if (await Permission.location.isUndetermined) { await Permission.location.request(); diff --git a/lib/home/activity_list_page.dart b/lib/home/activity_list_page.dart index 50edc487..d050c190 100644 --- a/lib/home/activity_list_page.dart +++ b/lib/home/activity_list_page.dart @@ -30,11 +30,6 @@ class _ActivityListPage extends State @override void initState() { super.initState(); - SharedPreferences.getInstance().then((value) => { - apiService = ApiService(Dio(), - context: context, token: value.getString('token')), - queryActivity(), - }); eventBus.on().listen((event) { if (event.type < 3) { @@ -46,6 +41,8 @@ class _ActivityListPage extends State List activityList; queryActivity() async { + final SharedPreferences value = await SharedPreferences.getInstance(); + apiService = ApiService(Dio(), context: context, token: value.getString('token')); BaseData> baseData = await apiService.informationList({ "pageNum": 1, "pageSize": 10, @@ -57,9 +54,7 @@ class _ActivityListPage extends State }); if (baseData != null && baseData.isSuccess) { _refreshController.refreshCompleted(); - setState(() { - activityList = baseData.data.list; - }); + activityList = baseData.data.list; } } @@ -88,40 +83,45 @@ class _ActivityListPage extends State }, ), onRefresh: queryActivity, - child: ListView.builder( - itemCount: activityList == null ? 0 : activityList.length, - physics: NeverScrollableScrollPhysics(), - itemBuilder: (context, position) { - return InkWell( - onTap: () { - Navigator.of(context).pushNamed('/router/store_detail_page', - arguments: {"activityId": activityList[position].id}); - }, - child: FrameSeparateWidget( - child: activityItem(activityList[position]), - placeHolder: AspectRatio( - aspectRatio: 1.34, - child: Container( - margin: EdgeInsets.only( - left: 16.w, right: 16.w, top: 8.h, bottom: 8.h), - decoration: BoxDecoration( - color: Colors.white, - boxShadow: [ - BoxShadow( - color: Colors.black.withAlpha(12), - offset: Offset(0, 3), - blurRadius: 14, - spreadRadius: 0, - ) - ], - borderRadius: BorderRadius.circular(8), + child: FutureBuilder( + future: queryActivity(), + builder: (context, snapshot) { + return ListView.builder( + itemCount: activityList == null ? 0 : activityList.length, + physics: NeverScrollableScrollPhysics(), + itemBuilder: (context, position) { + return InkWell( + onTap: () { + Navigator.of(context).pushNamed('/router/store_detail_page', + arguments: {"activityId": activityList[position].id}); + }, + child: FrameSeparateWidget( + child: activityItem(activityList[position]), + placeHolder: AspectRatio( + aspectRatio: 1.34, + child: Container( + margin: EdgeInsets.only( + left: 16.w, right: 16.w, top: 8.h, bottom: 8.h), + decoration: BoxDecoration( + color: Colors.white, + boxShadow: [ + BoxShadow( + color: Colors.black.withAlpha(12), + offset: Offset(0, 3), + blurRadius: 14, + spreadRadius: 0, + ) + ], + borderRadius: BorderRadius.circular(8), + ), + ), ), ), - ), - ), + ); + }, ); }, - ), + ) ), ), ); diff --git a/lib/home/home_page.dart b/lib/home/home_page.dart index 40274ab5..f82adf5f 100644 --- a/lib/home/home_page.dart +++ b/lib/home/home_page.dart @@ -1,6 +1,7 @@ import 'package:dio/dio.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_swiper/flutter_swiper.dart'; import 'package:huixiang/generated/l10n.dart'; @@ -46,14 +47,6 @@ class _HomePage extends State with AutomaticKeepAliveClientMixin { void initState() { super.initState(); - SharedPreferences.getInstance().then((value) => { - apiService = ApiService(Dio(), - context: context, - token: value.getString('token'), - showLoading: false), - queryHome(), - }); - eventBus.on().listen((event) { if (event.type < 3) { setState(() {}); @@ -84,9 +77,13 @@ class _HomePage extends State with AutomaticKeepAliveClientMixin { Founder founder; queryHome() async { - SmartDialog.showLoading( - msg: S.of(context).zhengzaijiazai, - animationDurationTemp: Duration(seconds: 1)); + // SmartDialog.showLoading(msg: S.of(context).zhengzaijiazai); + EasyLoading.show(status: S.of(context).zhengzaijiazai); + + final SharedPreferences value = await SharedPreferences.getInstance(); + apiService = ApiService(Dio(), context: context, + token: value.getString('token'), showLoading: false); + BaseData> baseData = await apiService.queryBanner({ "model": {"type": "HOME_PAGE"}, }).catchError((onError) { @@ -95,10 +92,7 @@ class _HomePage extends State with AutomaticKeepAliveClientMixin { if (baseData != null && baseData.isSuccess) { bannerData.clear(); bannerData.addAll(baseData.data.records); - setState(() { - if (bannerData.length > 0) - controller.move(0, animation: false); - }); + if (bannerData.length > 0) controller.move(0, animation: false); } BaseData brand = await apiService.queryHomeBrand().catchError((onError) { @@ -137,10 +131,10 @@ class _HomePage extends State with AutomaticKeepAliveClientMixin { gooods.clear(); gooods.addAll(goodsData.data.list); } - SmartDialog.dismiss(); + // SmartDialog.dismiss(); + EasyLoading.dismiss(); if (baseData != null && baseData.isSuccess) { refreshController.refreshCompleted(); - if (mounted) setState(() {}); } else { refreshController.refreshFailed(); } @@ -167,142 +161,147 @@ class _HomePage extends State with AutomaticKeepAliveClientMixin { onRefresh: queryHome, child: SingleChildScrollView( physics: NeverScrollableScrollPhysics(), - child: Column( - children: [ - banner(), - SizedBox( - height: 20.h, - ), - ItemTitle( - text: S.of(context).jinrihuiyuanrenwu, - imgPath: "assets/image/icon_today_task.png", - moreText: S.of(context).renwuzhongxin, - onTap: () { - SharedPreferences.getInstance().then((value) { - if (value.getString('token') == null || - value.getString('token') == "") { - loginTips(); - } else { - Navigator.of(context).pushNamed('/router/integral_page'); - } - }); - }, - ), - InkWell( - onTap: () { - SharedPreferences.getInstance().then((value) { - if (value.getString('token') == null || - value.getString('token') == "") { - loginTips(); - } else { - Navigator.of(context).pushNamed('/router/integral_page'); - } - }); - }, - child: signIn(), - ), - SizedBox( - height: 12.h, - ), - ItemTitle( - text: S.of(context).huixiangtoutiao, - imgPath: "assets/image/icon_today_video.png", - moreText: S.of(context).chakangengduo, - onTap: () { - Navigator.of(context).pushNamed('/router/hot_article_page'); - }, - ), - hotList(), - ItemTitle( - text: S.of(context).chuangshirendegushi1, - imgPath: "assets/image/icon_founder.png", - ), - GestureDetector( - onTap: () { - Navigator.of(context).pushNamed('/router/founder_story_page'); - }, - child: founderStore(), - ), - ItemTitle( - text: S.of(context).pinpaijieshao, - imgPath: "assets/image/icon_brand_introduction.png", - ), - brands(), - // ban(), - Container( - margin: EdgeInsets.only( - left: 16.5.w, right: 16.5.w, bottom: 40.h, top: 10.h), - padding: EdgeInsets.only(bottom: 10.h, top: 16.h), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(4), - boxShadow: [ - BoxShadow( - color: Colors.black.withAlpha(12), - offset: Offset(0, 3), - blurRadius: 14, - spreadRadius: 0, - ) - ], - color: Colors.white, - ), - child: Column( - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.center, + child: FutureBuilder( + future: queryHome(), + builder: (context, snapshot) { + return Column( + children: [ + banner(), + SizedBox( + height: 20.h, + ), + ItemTitle( + text: S.of(context).jinrihuiyuanrenwu, + imgPath: "assets/image/icon_today_task.png", + moreText: S.of(context).renwuzhongxin, + onTap: () { + SharedPreferences.getInstance().then((value) { + if (value.getString('token') == null || + value.getString('token') == "") { + loginTips(); + } else { + Navigator.of(context).pushNamed('/router/integral_page'); + } + }); + }, + ), + InkWell( + onTap: () { + SharedPreferences.getInstance().then((value) { + if (value.getString('token') == null || + value.getString('token') == "") { + loginTips(); + } else { + Navigator.of(context).pushNamed('/router/integral_page'); + } + }); + }, + child: signIn(), + ), + SizedBox( + height: 12.h, + ), + ItemTitle( + text: S.of(context).huixiangtoutiao, + imgPath: "assets/image/icon_today_video.png", + moreText: S.of(context).chakangengduo, + onTap: () { + Navigator.of(context).pushNamed('/router/hot_article_page'); + }, + ), + hotList(), + ItemTitle( + text: S.of(context).chuangshirendegushi1, + imgPath: "assets/image/icon_founder.png", + ), + GestureDetector( + onTap: () { + Navigator.of(context).pushNamed('/router/founder_story_page'); + }, + child: founderStore(), + ), + ItemTitle( + text: S.of(context).pinpaijieshao, + imgPath: "assets/image/icon_brand_introduction.png", + ), + brands(), + // ban(), + Container( + margin: EdgeInsets.only( + left: 16.5.w, right: 16.5.w, bottom: 40.h, top: 10.h), + padding: EdgeInsets.only(bottom: 10.h, top: 16.h), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(4), + boxShadow: [ + BoxShadow( + color: Colors.black.withAlpha(12), + offset: Offset(0, 3), + blurRadius: 14, + spreadRadius: 0, + ) + ], + color: Colors.white, + ), + child: Column( children: [ - Expanded( - flex: 1, - child: ItemTitle( - text: S.of(context).jifenshangcheng, - imgPath: "assets/image/icon_points_mall.png", - ), - ), - GestureDetector( - onTap: callback, - child: Container( - padding: EdgeInsets.symmetric( - vertical: 3.h, horizontal: 8.w), - margin: EdgeInsets.only(right: 16.w), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(11.5), - color: Color(0xFF32A060), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Expanded( + flex: 1, + child: ItemTitle( + text: S.of(context).jifenshangcheng, + imgPath: "assets/image/icon_points_mall.png", + ), ), - child: Row( - children: [ - Text( - "GO", - style: TextStyle( - fontSize: 14.sp, - fontWeight: FontWeight.bold, - color: Colors.white, - ), + GestureDetector( + onTap: callback, + child: Container( + padding: EdgeInsets.symmetric( + vertical: 3.h, horizontal: 8.w), + margin: EdgeInsets.only(right: 16.w), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(11.5), + color: Color(0xFF32A060), ), - Icon( - Icons.chevron_right, - color: Colors.white, - size: 18, + child: Row( + children: [ + Text( + "GO", + style: TextStyle( + fontSize: 14.sp, + fontWeight: FontWeight.bold, + color: Colors.white, + ), + ), + Icon( + Icons.chevron_right, + color: Colors.white, + size: 18, + ), + ], ), - ], + ), ), - ), + ], + ), + SizedBox( + height: 14.h, + ), + Divider( + // indent: 0.0, + thickness: 1, + color: Color(0xffF2F2F2), ), + integralStore(), ], ), - SizedBox( - height: 14.h, - ), - Divider( - // indent: 0.0, - thickness: 1, - color: Color(0xffF2F2F2), - ), - integralStore(), - ], - ), - ), - // integralStore(), - ], + ), + // integralStore(), + ], + ); + }, ), ), ), @@ -597,14 +596,14 @@ class _HomePage extends State with AutomaticKeepAliveClientMixin { return Container( height: 90.h, margin: EdgeInsets.only(bottom: 18.h), - child: ListView.builder( - padding: EdgeInsets.only(left: 10.w, right: 10.w), - scrollDirection: Axis.horizontal, + child: Swiper( physics: BouncingScrollPhysics(), + viewportFraction: 0.32, + scale: 0.7, itemBuilder: (context, position) { return Container( - height: 60.h, - width: 120.w, + // height: 60.h, + // width: 120.w, margin: EdgeInsets.symmetric(horizontal: 3.w, vertical: 15.h), decoration: BoxDecoration( color: Colors.white, @@ -630,6 +629,38 @@ class _HomePage extends State with AutomaticKeepAliveClientMixin { itemCount: (brandData != null && brandData.length > 0) ? brandData.length : 0, ), + // child: ListView.builder( + // padding: EdgeInsets.only(left: 10.w, right: 10.w), + // scrollDirection: Axis.horizontal, + // physics: BouncingScrollPhysics(), + // itemBuilder: (context, position) { + // return Container( + // height: 60.h, + // width: 120.w, + // margin: EdgeInsets.symmetric(horizontal: 3.w, vertical: 15.h), + // decoration: BoxDecoration( + // color: Colors.white, + // boxShadow: [ + // BoxShadow( + // color: Colors.black.withAlpha(37), + // offset: Offset(0, 2), + // blurRadius: 5, + // spreadRadius: 0, + // ) + // ], + // borderRadius: BorderRadius.circular(8), + // ), + // child: MImage( + // brandData != null ? brandData[position].image : "", + // radius: BorderRadius.circular(8), + // fit: BoxFit.cover, + // errorSrc: "assets/image/default_2_1.png", + // fadeSrc: "assets/image/default_2_1.png", + // ), + // ); + // }, + // itemCount: (brandData != null && brandData.length > 0) ? brandData.length : 0, + // ), ); } @@ -673,7 +704,9 @@ class _HomePage extends State with AutomaticKeepAliveClientMixin { ), ); }, - itemCount: (bannerData != null && bannerData.length > 0) ? bannerData.length : 1, + itemCount: (bannerData != null && bannerData.length > 0) + ? bannerData.length + : 1, ), ), ); diff --git a/lib/home/huixiang_brand_page.dart b/lib/home/huixiang_brand_page.dart index ba53605e..7b5877bc 100644 --- a/lib/home/huixiang_brand_page.dart +++ b/lib/home/huixiang_brand_page.dart @@ -3,6 +3,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; +import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_html/flutter_html.dart'; import 'package:flutter_html/image_render.dart'; import 'package:flutter_swiper/flutter_swiper.dart'; @@ -32,7 +33,9 @@ class BrandPage extends StatefulWidget { class _BrandPage extends State with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin { - ScrollController scrollController = ScrollController(); + + final ScrollController scrollController = ScrollController(); + final RefreshController refreshController = RefreshController(); ApiService apiService; List brands = []; @@ -40,11 +43,19 @@ class _BrandPage extends State List globaKeys = []; List bannerData = []; - // List brandText = []; var isShowMore = false; - queryHome() async { - BaseData baseData = await apiService.queryHome().catchError((error) { + Future queryHome() async { + EasyLoading.show(status: S + .of(context) + .zhengzaijiazai); + + final SharedPreferences value = await SharedPreferences.getInstance(); + apiService = ApiService(Dio(), context: context, + token: value.getString('token'), showLoading: false); + + BaseData baseData = await apiService.queryHome().catchError(( + error) { refreshController.refreshFailed(); }); BaseData> banner = await apiService.queryBanner({ @@ -55,9 +66,7 @@ class _BrandPage extends State bannerData.clear(); bannerData.addAll(banner.data.records); - BaseData brand = await apiService.queryHomeBrand().catchError((onError) { - refreshController.refreshFailed(); - }).catchError((onError) { + BaseData brand = await apiService.queryHomeBrand().catchError((error) { refreshController.refreshFailed(); }); if (brand != null && brand.isSuccess) { @@ -69,30 +78,27 @@ class _BrandPage extends State brands.forEach((element) { globaKeys.add(GlobalKey()); }); - setState(() {}); } else { refreshController.refreshFailed(); } - + EasyLoading.dismiss(); if (baseData != null && baseData.isSuccess) { refreshController.refreshCompleted(); brandData = baseData.data; - setState(() {}); } else { refreshController.refreshFailed(); } } + @override + void didChangeDependencies() { + super.didChangeDependencies(); + } + @override void initState() { super.initState(); - SharedPreferences.getInstance().then((value) => { - apiService = ApiService(Dio(), - context: context, token: value.getString('token')), - queryHome(), - }); - eventBus.on().listen((event) { print("object: BrandPage"); if (event.type < 3) { @@ -101,14 +107,15 @@ class _BrandPage extends State }); } - RefreshController refreshController = RefreshController(); - @override Widget build(BuildContext context) { super.build(context); return Scaffold( appBar: AppBar( - toolbarHeight: 40.h - MediaQuery.of(context).padding.top, + toolbarHeight: 40.h - MediaQuery + .of(context) + .padding + .top, backgroundColor: Colors.white, elevation: 0, ), @@ -132,8 +139,14 @@ class _BrandPage extends State child: Container( color: Color(0xFFF7F7F7), margin: EdgeInsets.only(top: 16.h), - child: Column( - children: homeChildItem(), + child: FutureBuilder( + future: queryHome(), + builder: (context, snapshot) { + //ConnectionState + return Column( + children: homeChildItem(), + ); + }, ), ), ), @@ -252,7 +265,7 @@ class _BrandPage extends State TextSpan(children: [ TextSpan( text: - brandData == null ? "" : brandData.originator, + brandData == null ? "" : brandData.originator, style: TextStyle( fontWeight: FontWeight.bold, fontSize: 14.sp, @@ -260,7 +273,9 @@ class _BrandPage extends State ), ), TextSpan( - text: " ${S.of(context).jituanchuangbanren}", + text: " ${S + .of(context) + .jituanchuangbanren}", style: TextStyle( fontSize: 10.sp, color: Colors.black, @@ -293,7 +308,9 @@ class _BrandPage extends State mainAxisSize: MainAxisSize.max, children: [ Text( - S.of(context).gengduo, + S + .of(context) + .gengduo, style: TextStyle( fontSize: 12.sp, color: Colors.black, @@ -353,7 +370,9 @@ class _BrandPage extends State height: 40.h, ), Text( - S.of(context).linian, + S + .of(context) + .linian, style: TextStyle( fontSize: 16.sp, fontWeight: FontWeight.bold, diff --git a/lib/home/points_mall_page.dart b/lib/home/points_mall_page.dart index b5e14c3f..f0472dbd 100644 --- a/lib/home/points_mall_page.dart +++ b/lib/home/points_mall_page.dart @@ -3,6 +3,7 @@ import 'dart:ui'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_swiper/flutter_swiper.dart'; import 'package:huixiang/generated/l10n.dart'; @@ -58,31 +59,16 @@ class _PointsMallPage extends State void initState() { super.initState(); - refreshUserInfo(); - eventBus.on().listen((event) { if (event.type < 3) { setState(() {}); } if (event.type == 3) { - refreshUserInfo(); + creditGoods(); } }); } - refreshUserInfo() { - if (mounted) - SharedPreferences.getInstance().then((value) => { - client = ApiService(Dio(), - context: context, - token: value.getString('token'), - showLoading: false), - SmartDialog.showLoading(msg: S.current.zhengzaijiazai), - creditGoods(categoryId), - queryUser(), - }); - } - int pageNum = 1; //排序类型枚举:1-自然排序,2-销量,3-价格 @@ -103,7 +89,6 @@ class _PointsMallPage extends State if (banner != null) { bannerData.clear(); bannerData.addAll(banner.data.records); - setState(() {}); } BaseData baseData = await client.queryInfo(); @@ -112,11 +97,18 @@ class _PointsMallPage extends State SharedPreferences.getInstance().then((value) => { value.setString('user', jsonEncode(baseData.data)), }); - setState(() {}); } } - creditGoods(categoryId) async { + creditGoods() async { + EasyLoading.show(status: S.current.zhengzaijiazai); + + final SharedPreferences value = await SharedPreferences.getInstance(); + client = ApiService(Dio(), + context: context, token: value.getString('token'), showLoading: false); + + await queryUser(); + BaseData> dataCategory = await client.goodsCategory({ "current": 1, @@ -149,21 +141,19 @@ class _PointsMallPage extends State _refreshController.loadFailed(); _refreshController.refreshFailed(); }); - SmartDialog.dismiss(); + EasyLoading.dismiss(); if (baseData != null && baseData.isSuccess) { if (pageNum == 1) { goods.clear(); } goods.addAll(baseData.data.list); - setState(() { - _refreshController.refreshCompleted(); - _refreshController.loadComplete(); - if (baseData.data.pageNum == baseData.data.pages) { - _refreshController.loadNoData(); - } else { - pageNum += 1; - } - }); + _refreshController.refreshCompleted(); + _refreshController.loadComplete(); + if (baseData.data.pageNum == baseData.data.pages) { + _refreshController.loadNoData(); + } else { + pageNum += 1; + } } else { _refreshController.loadFailed(); _refreshController.refreshFailed(); @@ -174,26 +164,12 @@ class _PointsMallPage extends State _refresh() { pageNum = 1; - SmartDialog.showLoading(msg: S.current.zhengzaijiazai); - creditGoods(categoryId); - queryUser(); + creditGoods(); } @override Widget build(BuildContext context) { super.build(context); - List> sortItems = []; - sortString.forEach((element) { - sortItems.add(DropdownMenuItem( - value: element, - child: Text( - element, - style: TextStyle( - fontSize: 12.sp, - fontWeight: FontWeight.w500, - color: Color(0xff353535)), - ))); - }); return SmartRefresher( enablePullDown: true, enablePullUp: true, @@ -208,85 +184,103 @@ class _PointsMallPage extends State controller: _refreshController, onRefresh: _refresh, onLoading: () { - SmartDialog.showLoading(msg: S.current.zhengzaijiazai); - creditGoods(categoryId); + creditGoods(); }, child: SingleChildScrollView( child: Container( - color: Color(0xFFFAFAFA), - child: Column( - children: [ - banner(), - userItem(), - ItemTitle( - text: S.of(context).jifenshangcheng, - imgPath: "assets/image/icon_points_mall.png", - moreText: _itemText, - moreType: 1, - items: sortItems, - onChanged: _sortChange, - ), - Container( - alignment: Alignment.centerLeft, - child: DefaultTabController( - length: gooodsCategorys == null ? 0 : gooodsCategorys.length, - child: TabBar( - isScrollable: true, - //可滚动 - indicatorColor: Color(0xff39B54A), - labelColor: Color(0xff32A060), - labelStyle: - TextStyle(fontSize: 14.sp, fontWeight: FontWeight.bold), - unselectedLabelStyle: TextStyle( - fontSize: 14.sp, - fontWeight: FontWeight.w400, + color: Color(0xFFFAFAFA), + child: FutureBuilder( + future: creditGoods(), + builder: (context, snapshot) { + return Column( + children: [ + banner(), + userItem(), + ItemTitle( + text: S.of(context).jifenshangcheng, + imgPath: "assets/image/icon_points_mall.png", + moreText: _itemText, + moreType: 1, + items: sortString + .map((e) => DropdownMenuItem( + value: e, + child: Text( + e, + style: TextStyle( + fontSize: 12.sp, + fontWeight: FontWeight.w500, + color: Color(0xff353535)), + ), + ), + ) + .toList(), + onChanged: _sortChange, ), - // controller: tabController, - //未选中文字颜色 - unselectedLabelColor: Color(0xff4D4D4D), - indicatorSize: TabBarIndicatorSize.label, - //指示器与文字等宽 - tabs: gooodsCategorys == null - ? [] - : gooodsCategorys - .map((e) => Tab(text: e.name)) - .toList(), - onTap: (index) { - categoryId = gooodsCategorys[index].id; - pageNum = 1; - creditGoods(categoryId); - }, - ), - ), - ), - GridView.builder( - itemCount: goods == null ? 0 : goods.length, - padding: EdgeInsets.only( - left: 16.w, right: 16.w, top: 13.h, bottom: 16.h), - shrinkWrap: true, - physics: NeverScrollableScrollPhysics(), - gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( - //一行的Widget数量 - crossAxisCount: 2, - //水平子Widget之间间距 - crossAxisSpacing: 11.w, - //垂直子Widget之间间距 - mainAxisSpacing: 16.w, - //子Widget宽高比例 0.59 - childAspectRatio: 166 / - (281 / 2 + (281 / 2) * AppUtils.textScale(context)), - ), - itemBuilder: (contetx, index) { - return GestureDetector( - onTap: () { - _toDetails(index); - }, - child: buildItem(goods[index]), - ); - }) - ], - ), - ), + Container( + alignment: Alignment.centerLeft, + child: DefaultTabController( + length: gooodsCategorys == null + ? 0 + : gooodsCategorys.length, + child: TabBar( + isScrollable: true, + //可滚动 + indicatorColor: Color(0xff39B54A), + labelColor: Color(0xff32A060), + labelStyle: TextStyle( + fontSize: 14.sp, fontWeight: FontWeight.bold), + unselectedLabelStyle: TextStyle( + fontSize: 14.sp, + fontWeight: FontWeight.w400, + ), + // controller: tabController, + //未选中文字颜色 + unselectedLabelColor: Color(0xff4D4D4D), + indicatorSize: TabBarIndicatorSize.label, + //指示器与文字等宽 + tabs: gooodsCategorys == null + ? [] + : gooodsCategorys + .map((e) => Tab(text: e.name)) + .toList(), + onTap: (index) { + categoryId = gooodsCategorys[index].id; + pageNum = 1; + creditGoods(); + }, + ), + ), + ), + GridView.builder( + itemCount: goods == null ? 0 : goods.length, + padding: EdgeInsets.only( + left: 16.w, right: 16.w, top: 13.h, bottom: 16.h), + shrinkWrap: true, + physics: NeverScrollableScrollPhysics(), + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + //一行的Widget数量 + crossAxisCount: 2, + //水平子Widget之间间距 + crossAxisSpacing: 11.w, + //垂直子Widget之间间距 + mainAxisSpacing: 16.w, + //子Widget宽高比例 0.59 + childAspectRatio: 166 / + (281 / 2 + + (281 / 2) * AppUtils.textScale(context)), + ), + itemBuilder: (contetx, index) { + return GestureDetector( + onTap: () { + _toDetails(index); + }, + child: buildItem(goods[index]), + ); + }) + ], + ); + }, + )), ), ); } @@ -323,8 +317,7 @@ class _PointsMallPage extends State orderDesc = false; break; } - SmartDialog.showLoading(msg: S.current.zhengzaijiazai); - creditGoods(categoryId); + creditGoods(); setState(() { _itemText = item; }); diff --git a/lib/integral/integral_detailed_page.dart b/lib/integral/integral_detailed_page.dart index bc3d1847..46c17e72 100644 --- a/lib/integral/integral_detailed_page.dart +++ b/lib/integral/integral_detailed_page.dart @@ -62,7 +62,7 @@ class _IntegralDetailedPage extends State void initState() { super.initState(); SharedPreferences.getInstance().then((value) => { - apiService = ApiService(Dio(), token: value.getString("token")), + apiService = ApiService(Dio(), context: context, token: value.getString("token")), userInfo = UserInfo.fromJson(jsonDecode(value.getString('user'))), queryDetail("bill_cate_point_get"), }); diff --git a/lib/integral/integral_page.dart b/lib/integral/integral_page.dart index 0fcfcd76..5aa524f1 100644 --- a/lib/integral/integral_page.dart +++ b/lib/integral/integral_page.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_swiper/flutter_swiper.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:huixiang/generated/l10n.dart'; @@ -43,9 +44,7 @@ class _IntegralPage extends State { token: value.getString("token"), showLoading: false); userinfo = UserInfo.fromJson(jsonDecode(value.getString("user"))); - SmartDialog.showLoading( - msg: S.of(context).zhengzaijiazai, - animationDurationTemp: Duration(seconds: 1)); + EasyLoading.show(status: S.of(context).zhengzaijiazai); querySignInfo(); }); } @@ -67,7 +66,8 @@ class _IntegralPage extends State { .indexWhere((element) => element.id == userinfo.memberRankVo.id) + 1); } - SmartDialog.dismiss(closeType: 3); + // SmartDialog.dismiss(closeType: 3); + EasyLoading.dismiss(); if (baseData != null && baseData.isSuccess) { signInfo = baseData.data; setState(() {}); @@ -508,7 +508,7 @@ class _IntegralPage extends State { SmartDialog.showToast("今日已签到了", alignment: Alignment.center); return; } - SmartDialog.showLoading(msg: S.of(context).zhengzaijiazai); + EasyLoading.show(status: S.of(context).zhengzaijiazai); BaseData baseData = await apiService.signIn(); if (baseData != null && baseData.isSuccess) { querySignInfo(); @@ -516,7 +516,7 @@ class _IntegralPage extends State { widget: SignInWidget("${signInfo.signInList.length + 1}", "${signInfo.rewardList[signInfo.signInList.length]}")); } else { - SmartDialog.dismiss(); + EasyLoading.dismiss(); } } diff --git a/lib/login/login_page.dart b/lib/login/login_page.dart index 2ed589eb..2b660176 100644 --- a/lib/login/login_page.dart +++ b/lib/login/login_page.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'dart:io'; import 'dart:ui'; import 'package:flutter/gestures.dart'; +import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:huixiang/main.dart'; import 'package:huixiang/retrofit/data/base_data.dart'; @@ -68,7 +69,7 @@ class _MyLoginPageState extends State with TickerProviderStateMixin { sharedPreferences.getString("token") != "") { Navigator.of(context).popAndPushNamed('/router/main_page'); } else { - client = ApiService(Dio()); + client = ApiService(Dio(), context: context); isShowLogin = true; setState(() {}); } @@ -274,13 +275,13 @@ class _MyLoginPageState extends State with TickerProviderStateMixin { "capcha": code, "mobile": mobile, }; - SmartDialog.showLoading(msg: S.of(context).zhengzaijiazai); + EasyLoading.show(status: S.of(context).zhengzaijiazai); BaseData value = await client.memberLogin(param).catchError((error) { print(error); SmartDialog.showToast("$error", alignment: Alignment.center); }); Future.delayed(Duration(seconds: 2), () { - SmartDialog.dismiss(); + EasyLoading.dismiss(); if (value.isSuccess) { saveUserJson(value.data); eventBus.fire(EventType(3)); diff --git a/lib/main.dart b/lib/main.dart index ed0da982..74b01e1d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -6,6 +6,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bmflocation/bdmap_location_flutter_plugin.dart'; +import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:huixiang/address/address_map_page.dart'; import 'package:huixiang/address/edit_address_page.dart'; @@ -167,14 +168,17 @@ class MyApp extends StatelessWidget { supportedLocales: S.delegate.supportedLocales, home: (isFirst ?? true) ? GuidePage() : LoginPage(), // home: MainPage(), - builder: (context, widget) { - return MediaQuery( - data: MediaQuery.of(context).copyWith( - textScaleFactor: AppUtils.textScale(context), - ), - child: FlutterSmartDialog(child: widget), - ); - }, + //EasyLoading.init(); + builder: EasyLoading.init( + builder: (context, widget) { + return MediaQuery( + data: MediaQuery.of(context).copyWith( + textScaleFactor: AppUtils.textScale(context), + ), + child: FlutterSmartDialog(child: widget), + ); + }, + ), onGenerateRoute: (settings) { final String name = settings.name; final Function pageContentBuilder = routers[name]; diff --git a/lib/main_page.dart b/lib/main_page.dart index 666d4b9f..9bb26082 100644 --- a/lib/main_page.dart +++ b/lib/main_page.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/home/huixiang_brand_page.dart'; import 'package:huixiang/home/main_home_page.dart'; @@ -57,6 +58,20 @@ class _MainPage extends State with WidgetsBindingObserver { super.initState(); WidgetsBinding.instance.addObserver(this); + + EasyLoading.instance + ..indicatorType = EasyLoadingIndicatorType.circle + // ..indicatorType = EasyLoadingIndicatorType.wave + // ..indicatorType = EasyLoadingIndicatorType.threeBounce + ..loadingStyle = EasyLoadingStyle.dark + ..indicatorSize = 35.0 + ..backgroundColor = Colors.white + ..progressColor = Colors.green + ..progressWidth = 3.0 + ..userInteractions = false + ..dismissOnTap = false; + + pushRoute(); _widgetOptions = [ @@ -189,7 +204,7 @@ class _MainPage extends State with WidgetsBindingObserver { } } - PageController pageController = PageController(initialPage: 1); + final PageController pageController = PageController(initialPage: 1); @override Widget build(BuildContext context) { diff --git a/lib/mine/mine_page.dart b/lib/mine/mine_page.dart index c1baa23c..f8dcb191 100644 --- a/lib/mine/mine_page.dart +++ b/lib/mine/mine_page.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/main.dart'; @@ -28,6 +29,10 @@ class MinePage extends StatefulWidget { class _MinePage extends State with AutomaticKeepAliveClientMixin { ApiService apiService; + UserInfo userinfo; + int rankLevel = 1; + List ranks = []; + final RefreshController _refreshController = RefreshController(); _toUserInfo() async { SharedPreferences shared = await SharedPreferences.getInstance(); @@ -63,43 +68,30 @@ class _MinePage extends State with AutomaticKeepAliveClientMixin { @override void initState() { super.initState(); - refreshUserInfo(); + eventBus.on().listen((event) { print("EventType: ${event.type}"); if (event.type < 3) { setState(() {}); } if (event.type == 3) { - refreshUserInfo(); + queryUserInfo(); } }); } - refreshUserInfo() { - if (mounted) - SharedPreferences.getInstance().then( - (value) => { - apiService = ApiService(Dio(), - context: context, - token: value.getString('token'), - showLoading: false), - if (value.containsKey('user') && - value.getString('user') != null && - value.getString('user') != "") - { - userinfo = UserInfo.fromJson(jsonDecode(value.getString('user'))), - }, - queryUserInfo() - }, - ); - } + queryUserInfo() async { + EasyLoading.show(status: S.of(context).zhengzaijiazai); - UserInfo userinfo; - int rankLevel = 1; - List ranks = []; + final SharedPreferences value = await SharedPreferences.getInstance(); + if (value.containsKey('user') && + value.getString('user') != null && + value.getString('user') != "") { + userinfo = UserInfo.fromJson(jsonDecode(value.getString('user'))); + } + apiService = ApiService(Dio(), context: context, + token: value.getString('token'), showLoading: false); - queryUserInfo() async { - SmartDialog.showLoading(msg: S.of(context).zhengzaijiazai, animationDurationTemp: Duration(seconds: 1)); BaseData> rankData = await apiService.rankList(); if (rankData != null && rankData.isSuccess) { ranks.clear(); @@ -126,12 +118,9 @@ class _MinePage extends State with AutomaticKeepAliveClientMixin { } else { _refreshController.refreshFailed(); } - SmartDialog.dismiss(); - if (mounted) setState(() {}); + EasyLoading.dismiss(); } - RefreshController _refreshController = RefreshController(); - @override Widget build(BuildContext context) { super.build(context); @@ -152,82 +141,90 @@ class _MinePage extends State with AutomaticKeepAliveClientMixin { child: Stack( alignment: Alignment.centerRight, children: [ - Column( - children: [ - Container( - margin: EdgeInsets.only(right: 16.w), - alignment: Alignment.centerRight, - child: Row( - mainAxisAlignment: MainAxisAlignment.end, + FutureBuilder( + future: queryUserInfo(), + builder: (context, snapshot) { + return Column( children: [ - // Container( - // margin: EdgeInsets.all(8.h), - // child: Image.asset( - // "assets/image/icon_notices.png", - // width: 24.w, - // height: 24.h, - // ), - // ), + Container( + margin: EdgeInsets.only(right: 16.w), + alignment: Alignment.centerRight, + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + // Container( + // margin: EdgeInsets.all(8.h), + // child: Image.asset( + // "assets/image/icon_notices.png", + // width: 24.w, + // height: 24.h, + // ), + // ), + InkWell( + onTap: () {}, + child: Container( + margin: EdgeInsets.all(8.h), + child: Image.asset( + "assets/image/icon_scan_qr_code.png", + width: 24.w, + height: 24.h, + ), + ), + ), + ], + ), + ), InkWell( - onTap: () {}, - child: Container( - margin: EdgeInsets.all(8.h), - child: Image.asset( - "assets/image/icon_scan_qr_code.png", - width: 24.w, - height: 24.h, + onTap: _toUserInfo, + child: mineView(), + ), + SizedBox( + height: 22.h, + ), + GestureDetector( + onTap: () { + SharedPreferences.getInstance().then((value) { + if (value.getString("token") == null || + value.getString("token") == "") { + loginTips(); + return; + } + Navigator.of(context).pushNamed( + '/router/mine_vip_level_page', + arguments: { + "rankLevel": rankLevel, + "createTime": (userinfo != null) + ? "${userinfo.createTime}" + : "", + "points": (userinfo != null) + ? int.tryParse(userinfo.points) + : 0, + }); + }); + }, + child: Hero( + tag: "vip", + child: MineVipView( + rankLevel, + curLevel: rankLevel, + rank: (userinfo != null) + ? int.tryParse(userinfo.points) + : 0, + rankMax: (userinfo != null && + userinfo.memberRankVo != null) + ? userinfo.memberRankVo.rankOrigin + : 0, + createTime: (userinfo != null) + ? userinfo.createTime + : "", ), ), ), + orderOrCard(), + mineList(context), ], - ), - ), - InkWell( - onTap: _toUserInfo, - child: mineView(), - ), - SizedBox( - height: 22.h, - ), - GestureDetector( - onTap: () { - SharedPreferences.getInstance().then((value) { - if (value.getString("token") == null || - value.getString("token") == "") { - loginTips(); - return; - } - Navigator.of(context).pushNamed( - '/router/mine_vip_level_page', - arguments: { - "rankLevel": rankLevel, - "createTime": (userinfo != null) - ? "${userinfo.createTime}" - : "", - "points": (userinfo != null) - ? int.tryParse(userinfo.points) - : 0, - }); - }); - }, - child: MineVipView( - rankLevel, - curLevel: rankLevel, - rank: (userinfo != null) - ? int.tryParse(userinfo.points) - : 0, - rankMax: (userinfo != null && - userinfo.memberRankVo != null) - ? userinfo.memberRankVo.rankOrigin - : 0, - createTime: - (userinfo != null) ? userinfo.createTime : "", - ), - ), - orderOrCard(), - mineList(context), - ], - ), + ); + }), // buildNotice(), ], ), diff --git a/lib/mine/mine_vip_level_page.dart b/lib/mine/mine_vip_level_page.dart index 4732c5e5..9a64530a 100644 --- a/lib/mine/mine_vip_level_page.dart +++ b/lib/mine/mine_vip_level_page.dart @@ -1,4 +1,3 @@ - import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; @@ -68,23 +67,41 @@ class _MineVipLevelPage extends State { child: Column( children: [ Container( - height: 224.h , + height: 224.h, child: Swiper( viewportFraction: 0.95, loop: false, physics: BouncingScrollPhysics(), controller: controller, itemBuilder: (context, position) { - return MineVipView( - position + 1, - curLevel: widget.arguments["rankLevel"], - padding: 6.w, - rank: widget.arguments["points"], - rankMax: (position < (ranks.length - 1)) ? ranks[position + 1].rankOrigin : ranks[position].rankOrigin, - createTime: widget.arguments["createTime"], - ); + if (widget.arguments["rankLevel"] == (position + 1) || !(ranks != null && ranks.isNotEmpty)) { + return Hero( + tag: "vip", + child: MineVipView( + !(ranks != null && ranks.isNotEmpty) ? widget.arguments["rankLevel"] : position + 1, + curLevel: widget.arguments["rankLevel"], + padding: 6.w, + rank: !(ranks != null && ranks.isNotEmpty) ? 0 : widget.arguments["points"], + rankMax: !(ranks != null && ranks.isNotEmpty) ? 0 : (position < (ranks.length - 1)) + ? ranks[position + 1].rankOrigin + : ranks[position].rankOrigin, + createTime: widget.arguments["createTime"], + ), + ); + } else { + return MineVipView( + position + 1, + curLevel: widget.arguments["rankLevel"], + padding: 6.w, + rank: widget.arguments["points"], + rankMax: (position < (ranks.length - 1)) + ? ranks[position + 1].rankOrigin + : ranks[position].rankOrigin, + createTime: widget.arguments["createTime"], + ); + } }, - itemCount: (ranks != null && ranks.isNotEmpty) ? ranks.length : 0, + itemCount: (ranks != null && ranks.isNotEmpty) ? ranks.length : 1, ), ), Container( @@ -180,11 +197,13 @@ class _MineVipLevelPage extends State { crossAxisAlignment: CrossAxisAlignment.center, children: ranks != null ? ranks.map((e) { - return levelItem( - e, ranks[ranks.indexOf(e)].rankOrigin, - ranks.indexOf(e) == (ranks.length - 1) - ? 0 : ranks[ranks.indexOf(e) + 1].rankOrigin); - }).toList() + return levelItem( + e, + ranks[ranks.indexOf(e)].rankOrigin, + ranks.indexOf(e) == (ranks.length - 1) + ? 0 + : ranks[ranks.indexOf(e) + 1].rankOrigin); + }).toList() : [], ), SizedBox( diff --git a/lib/order/order_history_page.dart b/lib/order/order_history_page.dart index a3319f10..75f3e3c0 100644 --- a/lib/order/order_history_page.dart +++ b/lib/order/order_history_page.dart @@ -201,7 +201,7 @@ class _OrderHistoryList extends State super.initState(); SharedPreferences.getInstance().then((value) => { - apiService = ApiService(Dio(), token: value.getString("token")), + apiService = ApiService(Dio(), context: context, token: value.getString("token")), queryOrder(), }); } @@ -210,16 +210,17 @@ class _OrderHistoryList extends State return Container( margin: EdgeInsets.fromLTRB(16.w, 8.h, 16.w, 8.h), decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(4), - boxShadow: [ - BoxShadow( - color: Colors.black.withAlpha(25), - offset: Offset(0, 1), - blurRadius: 12, - spreadRadius: 0, - ) - ]), + color: Colors.white, + borderRadius: BorderRadius.circular(4), + boxShadow: [ + BoxShadow( + color: Colors.black.withAlpha(25), + offset: Offset(0, 1), + blurRadius: 12, + spreadRadius: 0, + ) + ], + ), child: Column( mainAxisAlignment: MainAxisAlignment.spaceAround, crossAxisAlignment: CrossAxisAlignment.start, @@ -429,37 +430,49 @@ class _OrderHistoryList extends State orderInfo.sendStatus, orderInfo.refundStatus, orderInfo.dayFlowCode, (type) { - if (type == 0) { - String storeId = - (orderInfo != null && orderInfo.storeVO != null) - ? (orderInfo.storeVO.id ?? "") - : ""; - aginOrder(storeId); - } else if (type == 1) { - SmartDialog.show(widget: Tips((){ + if (type == 0) { + String storeId = (orderInfo != null && + orderInfo.storeVO != null) + ? (orderInfo.storeVO.id ?? "") + : ""; + aginOrder(storeId); + } else if (type == 1) { + SmartDialog.show( + widget: Tips( + () { SmartDialog.dismiss(); - }, text: "暂不支持此功能",)); - } else if (type == 2) { - SmartDialog.show(widget: Tips((){ + }, + text: "暂不支持此功能", + )); + } else if (type == 2) { + SmartDialog.show( + widget: Tips( + () { SmartDialog.dismiss(); - }, text: "暂不支持此功能",)); - } else if (type == 3) { - SmartDialog.show(widget: Tips((){ + }, + text: "暂不支持此功能", + )); + } else if (type == 3) { + SmartDialog.show( + widget: Tips( + () { SmartDialog.dismiss(); - }, text: "暂不支持此功能",)); - } else if (type == 4) { - Navigator.of(context).pushNamed( - '/router/logistics_information_page', - arguments: { - "logisticsNum": orderInfo.logisticsNum, - "logisticsName": orderInfo.logisticsName, - "shipperCode": orderInfo.shipperCode, - "productNum": orderInfo.productList.length, - "skuImg": orderInfo.productList.length > 0 + }, + text: "暂不支持此功能", + )); + } else if (type == 4) { + Navigator.of(context).pushNamed( + '/router/logistics_information_page', + arguments: { + "logisticsNum": orderInfo.logisticsNum, + "logisticsName": orderInfo.logisticsName, + "shipperCode": orderInfo.shipperCode, + "productNum": orderInfo.productList.length, + "skuImg": orderInfo.productList.length > 0 ? orderInfo.productList[0].skuImg - : "" - }); - } + : "" + }); + } }) : [], ), @@ -473,8 +486,8 @@ class _OrderHistoryList extends State } aginOrder(storeId) { - Navigator.of(context).pushNamed('/router/union_detail_page', - arguments: {"id": storeId}); + Navigator.of(context) + .pushNamed('/router/union_detail_page', arguments: {"id": storeId}); } String totalPrice(orderInfo) { diff --git a/lib/order/store_selector_page.dart b/lib/order/store_selector_page.dart index 6a98b3df..9b037b6a 100644 --- a/lib/order/store_selector_page.dart +++ b/lib/order/store_selector_page.dart @@ -7,6 +7,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; import 'package:flutter_baidu_mapapi_utils/flutter_baidu_mapapi_utils.dart'; import 'package:flutter_bmflocation/bdmap_location_flutter_plugin.dart'; +import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/retrofit/data/base_data.dart'; @@ -119,12 +120,10 @@ class _StoreSelectorPage extends State { if (await Permission.location.isPermanentlyDenied) { requestDialog(); } else if (await Permission.location.isGranted) { - SmartDialog.showLoading( - msg: S.of(context).zhengzaijiazai, - animationDurationTemp: Duration(seconds: 1)); + EasyLoading.show(status: S.of(context).zhengzaijiazai); aMapFlutterLocation.startLocation(); Future.delayed(Duration(seconds: 6), () { - SmartDialog.dismiss(); + EasyLoading.dismiss(); }); } else if (await Permission.location.isUndetermined) { await Permission.location.request(); diff --git a/lib/retrofit/retrofit_api.dart b/lib/retrofit/retrofit_api.dart index 50f3f4b9..51a4a3bb 100644 --- a/lib/retrofit/retrofit_api.dart +++ b/lib/retrofit/retrofit_api.dart @@ -5,6 +5,7 @@ import 'package:dio/dio.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/retrofit/data/activity.dart'; @@ -70,9 +71,10 @@ abstract class ApiService { debugPrint("method = ${options.method.toString()}"); debugPrint("url = ${options.uri.toString()}"); debugPrint("headers = ${options.headers}"); - if (showLoading) { + if (showLoading && !EasyLoading.isShow) { //是否显示loading - SmartDialog.showLoading(msg: S.current.zhengzaijiazai); + // SmartDialog.showLoading(msg: S.current.zhengzaijiazai); + EasyLoading.show(status: S.of(context).zhengzaijiazai); } if (options.data is FormData) { debugPrint("params data = FormData"); @@ -81,8 +83,10 @@ abstract class ApiService { } debugPrint("params queryParameters = ${options.queryParameters}"); }, onResponse: (Response response) { - if (showLoading) { - SmartDialog.dismiss(); + if (showLoading && EasyLoading.isShow) { + + // SmartDialog.dismiss(); + EasyLoading.dismiss(); } debugPrint("\n====================== 响应数据开始 ====================="); debugPrint("code = ${response.statusCode}"); @@ -112,8 +116,9 @@ abstract class ApiService { } debugPrint("======================= 响应数据结束 =======================\n"); }, onError: (DioError e) { - if (showLoading) { - SmartDialog.dismiss(); + // SmartDialog.dismiss(); + if (EasyLoading.isShow) { + EasyLoading.dismiss(); } debugPrint("\n=======================错误响应数据 ========================"); debugPrint("type = ${e.type}"); diff --git a/lib/union/store_details_page.dart b/lib/union/store_details_page.dart index b3650959..284beb1a 100644 --- a/lib/union/store_details_page.dart +++ b/lib/union/store_details_page.dart @@ -283,7 +283,8 @@ class _StoreDetailsPage extends State }); if (baseData != null && baseData.isSuccess) { commentTextController.text = ""; - queryMemberCommentList(); + await queryMemberCommentList(); + toComment(); } } diff --git a/lib/union/union_details_page.dart b/lib/union/union_details_page.dart index 2e6c2f3b..552e8077 100644 --- a/lib/union/union_details_page.dart +++ b/lib/union/union_details_page.dart @@ -5,6 +5,7 @@ import 'package:dio/dio.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; +import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_swiper/flutter_swiper.dart'; import 'package:huixiang/generated/l10n.dart'; @@ -49,21 +50,14 @@ class _UnionDetailsPage extends State { refreshController.dispose(); } - @override - void initState() { - super.initState(); - - SharedPreferences.getInstance().then((value) => { - apiService = ApiService(Dio(), - context: context, token: value.getString('token')), - queryStoreInfo(), - }); - } - StoreInfo storeInfo; List activitys; queryStoreInfo() async { + final SharedPreferences value = await SharedPreferences.getInstance(); + apiService = + ApiService(Dio(), context: context, token: value.getString('token')); + BaseData baseData = await apiService .queryStoreInfo(widget.arguments["id"]) .catchError((error) { @@ -75,278 +69,293 @@ class _UnionDetailsPage extends State { activitys = storeInfo.informationVOPageVO.list .map((e) => Activity.fromJson(e)) .toList(); - if (mounted) setState(() {}); } else { refreshController.refreshFailed(); } } - RefreshController refreshController = RefreshController(); + final RefreshController refreshController = RefreshController(); @override Widget build(BuildContext context) { return Scaffold( appBar: MyAppBar( background: Color(0xFFF7F7F7), - title: storeInfo == null ? "" : storeInfo.storeName, + title: storeInfo == null ? widget.arguments["storeName"] : storeInfo.storeName, titleColor: Colors.black87, titleSize: 18.sp, leadingColor: Colors.black, ), - body: Column( - children: [ - Expanded( - child: SmartRefresher( - controller: refreshController, - enablePullDown: true, - enablePullUp: false, - header: MyHeader(), - physics: BouncingScrollPhysics(), - onRefresh: queryStoreInfo, - child: SingleChildScrollView( - physics: NeverScrollableScrollPhysics(), - child: Column( - children: [ - AspectRatio( - aspectRatio: 1, - child: Container( - margin: EdgeInsets.fromLTRB(16, 20, 16, 8), - padding: EdgeInsets.fromLTRB(10, 20, 10, 14), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.all(Radius.circular(8)), - boxShadow: [ - BoxShadow( - color: Colors.black.withAlpha(25), - offset: Offset(0, 1), - blurRadius: 12, - spreadRadius: 0, - ), - ], - ), - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceAround, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - AspectRatio( - aspectRatio: 1.8, - child: buildSwiper(), + body: FutureBuilder( + future: queryStoreInfo(), + builder: (context, snapshot) { + return Column( + children: [ + Expanded( + child: SmartRefresher( + controller: refreshController, + enablePullDown: true, + enablePullUp: false, + header: MyHeader(), + physics: BouncingScrollPhysics(), + onRefresh: queryStoreInfo, + child: SingleChildScrollView( + physics: NeverScrollableScrollPhysics(), + child: Column( + children: [ + AspectRatio( + aspectRatio: 1, + child: Container( + margin: EdgeInsets.fromLTRB(16, 20, 16, 8), + padding: EdgeInsets.fromLTRB(10, 20, 10, 14), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(8), + boxShadow: [ + BoxShadow( + color: Colors.black.withAlpha(25), + offset: Offset(0, 1), + blurRadius: 12, + spreadRadius: 0, + ), + ], ), - Expanded( - child: Container( - margin: EdgeInsets.only( - left: 10.w, - right: 10.w, - top: 16.h, + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceAround, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + AspectRatio( + aspectRatio: 1.8, + child: buildSwiper(), ), - child: Column( - mainAxisAlignment: - MainAxisAlignment.spaceBetween, - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Row( + Expanded( + child: Container( + margin: EdgeInsets.only( + left: 10.w, + right: 10.w, + top: 16.h, + ), + child: Column( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + crossAxisAlignment: + CrossAxisAlignment.start, children: [ + Row( + children: [ + Text( + storeInfo != null + ? storeInfo.storeName + : "", + style: TextStyle( + fontSize: 16.sp, + color: Colors.black, + fontWeight: FontWeight.w500, + ), + ), + Expanded( + child: Container( + alignment: + Alignment.centerRight, + child: Text( + S.of(context).ren( + storeInfo != null + ? storeInfo + .perCapitaConsumption + : "", + ), + style: TextStyle( + fontSize: 14.sp, + fontWeight: FontWeight.w400, + color: Color(0xFF353535), + ), + ), + ), + ), + ], + ), Text( storeInfo != null - ? storeInfo.storeName + ? storeInfo.address : "", + maxLines: 2, + textAlign: TextAlign.justify, style: TextStyle( - fontSize: 16.sp, - color: Colors.black, - fontWeight: FontWeight.w500, + color: Color(0xFF353535), + fontWeight: FontWeight.w400, + fontSize: 12.sp, + ), + ), + Row( + children: itemServer( + storeInfo != null + ? storeInfo.businessService + : "", ), ), - Expanded( - child: Container( - alignment: Alignment.centerRight, - child: Text( - S.of(context).ren( - storeInfo != null - ? storeInfo - .perCapitaConsumption - : "", + Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + crossAxisAlignment: + CrossAxisAlignment.end, + children: [ + Expanded( + child: Text( + S.of(context).yingyeshijian(storeInfo == + null + ? "" + : (storeInfo.openStartTime == + null && + storeInfo + .openEndTime == + null) + ? S.of(context).quantian + : "${storeInfo.openStartTime.substring(0, storeInfo.openStartTime.lastIndexOf(":"))} " + "- ${storeInfo.openEndTime.substring(0, storeInfo.openEndTime.lastIndexOf(":"))}"), + style: TextStyle( + color: Color(0xFF353535), + fontWeight: FontWeight.w400, + fontSize: 12.sp, + ), ), - style: TextStyle( - fontSize: 14.sp, - fontWeight: FontWeight.w400, - color: Color(0xFF353535), + ), + SizedBox( + width: 16.w, + ), + InkWell( + onTap: () { + if (storeInfo == null || + storeInfo.latitude == + null || + storeInfo.longitude == + null || + storeInfo.latitude == "" || + storeInfo.longitude == "") + return; + Navigator.of(context).pushNamed( + '/router/location_map', + arguments: { + "lat": storeInfo.latitude, + "lng": + storeInfo.longitude, + "storeName": + storeInfo.storeName, + }); + }, + child: Image.asset( + "assets/image/icon_union_location.png", + width: 24.w, + height: 24.h, ), ), - ), - ), - ], - ), - Text( - storeInfo != null - ? storeInfo.address - : "", - maxLines: 2, - textAlign: TextAlign.justify, - style: TextStyle( - color: Color(0xFF353535), - fontWeight: FontWeight.w400, - fontSize: 12.sp, - ), - ), - Row( - children: itemServer( - storeInfo != null - ? storeInfo.businessService : "", - ), - ), - Row( - mainAxisAlignment: - MainAxisAlignment.spaceBetween, - crossAxisAlignment: - CrossAxisAlignment.end, - children: [ - Expanded( - child: Text( - S.of(context).yingyeshijian(storeInfo == null - ? "" : (storeInfo.openStartTime == null && storeInfo.openEndTime == null) - ? S.of(context).quantian - : "${storeInfo.openStartTime.substring(0, storeInfo.openStartTime.lastIndexOf(":"))} " - "- ${storeInfo.openEndTime.substring(0, storeInfo.openEndTime.lastIndexOf(":"))}"), - style: TextStyle( - color: Color(0xFF353535), - fontWeight: FontWeight.w400, - fontSize: 12.sp, + SizedBox( + width: 16.w, ), - ), - ), - SizedBox( - width: 16.w, - ), - InkWell( - onTap: () { - if (storeInfo == null || - storeInfo.latitude == null || - storeInfo.longitude == null || - storeInfo.latitude == "" || - storeInfo.longitude == "") - return; - Navigator.of(context).pushNamed( - '/router/location_map', - arguments: { - "lat": storeInfo.latitude, - "lng": storeInfo.longitude, - "storeName": - storeInfo.storeName, - }); - }, - child: Image.asset( - "assets/image/icon_union_location.png", - width: 24.w, - height: 24.h, - ), - ), - SizedBox( - width: 16.w, - ), - InkWell( - onTap: () { - showCallMobile(); - }, - child: Image.asset( - "assets/image/icon_union_call.png", - width: 24, - height: 24, - ), + InkWell( + onTap: () { + showCallMobile(); + }, + child: Image.asset( + "assets/image/icon_union_call.png", + width: 24, + height: 24, + ), + ), + ], ), ], ), - ], + ), + flex: 1, ), - ), - flex: 1, + ], ), - ], + ), ), - ), - ), - buildVip(), - Container( - margin: EdgeInsets.only(top: 10.h, bottom: 10.h), - child: ItemTitle( - text: S.of(context).youhuiquan, - imgPath: "assets/image/icon_union_coupons.png", - ), - ), - (storeInfo != null && storeInfo.couponVOList != null) - ? buildCoupon() - : Container( - width: double.infinity, - height: 50.h, - alignment: Alignment.center, - child: Text( - S.of(context).zanwuyouhuiquankelingqu, - style: TextStyle( - fontSize: 14.sp, - fontWeight: FontWeight.bold, - color: Color(0xFFA0A0A0), - ), - ), + buildVip(), + Container( + margin: EdgeInsets.only(top: 10.h, bottom: 10.h), + child: ItemTitle( + text: S.of(context).youhuiquan, + imgPath: "assets/image/icon_union_coupons.png", ), - Container( - margin: EdgeInsets.only(top: 20.h, bottom: 20.h), - child: ItemTitle( - text: S.of(context).xindianhuodong, - imgPath: "assets/image/icon_union_start_store.png", - ), - ), - (activitys != null && activitys.length > 0) - ? Container( - margin: EdgeInsets.only(bottom: 30.h), - child: AspectRatio( - aspectRatio: 1.55, - child: buildSwiper2Bottom(), - ), - ) - : Container( - width: double.infinity, - height: 30.h, - margin: EdgeInsets.only(bottom: 30.h), - alignment: Alignment.center, - child: Text( - S.of(context).muqianzanwuxingdianhuodong, - style: TextStyle( - fontSize: 14.sp, - fontWeight: FontWeight.bold, - color: Color(0xFFA0A0A0), + ), + (storeInfo != null && storeInfo.couponVOList != null) + ? buildCoupon() + : Container( + width: double.infinity, + height: 50.h, + alignment: Alignment.center, + child: Text( + S.of(context).zanwuyouhuiquankelingqu, + style: TextStyle( + fontSize: 14.sp, + fontWeight: FontWeight.bold, + color: Color(0xFFA0A0A0), + ), + ), ), - ), + Container( + margin: EdgeInsets.only(top: 20.h, bottom: 20.h), + child: ItemTitle( + text: S.of(context).xindianhuodong, + imgPath: "assets/image/icon_union_start_store.png", ), - ], - ), - ), - ), - flex: 1, - ), - InkWell( - onTap: _loginMin, - child: Container( - padding: EdgeInsets.only(top: 16.h, bottom: 16.h), - decoration: BoxDecoration( - color: isEnable() ? Color(0xFF32A060) : Color(0xFFD8D8D8), - borderRadius: BorderRadius.vertical( - top: Radius.circular(4), + ), + (activitys != null && activitys.length > 0) + ? Container( + margin: EdgeInsets.only(bottom: 30.h), + child: AspectRatio( + aspectRatio: 1.55, + child: buildSwiper2Bottom(), + ), + ) + : Container( + width: double.infinity, + height: 30.h, + margin: EdgeInsets.only(bottom: 30.h), + alignment: Alignment.center, + child: Text( + S.of(context).muqianzanwuxingdianhuodong, + style: TextStyle( + fontSize: 14.sp, + fontWeight: FontWeight.bold, + color: Color(0xFFA0A0A0), + ), + ), + ), + ], + ), + ), ), + flex: 1, ), - alignment: Alignment.center, - child: Text( - isEnable() - ? S.of(context).jinrushangdian - : S.of(context).zanwuxianshangjindian, - style: TextStyle( - fontSize: 16.sp, - color: isEnable() ? Colors.white : Color(0xFFA0A0A0), - fontWeight: FontWeight.bold, + InkWell( + onTap: _loginMin, + child: Container( + padding: EdgeInsets.only(top: 16.h, bottom: 16.h), + decoration: BoxDecoration( + color: isEnable() ? Color(0xFF32A060) : Color(0xFFD8D8D8), + borderRadius: BorderRadius.vertical( + top: Radius.circular(4), + ), + ), + alignment: Alignment.center, + child: Text( + isEnable() + ? S.of(context).jinrushangdian + : S.of(context).zanwuxianshangjindian, + style: TextStyle( + fontSize: 16.sp, + color: isEnable() ? Colors.white : Color(0xFFA0A0A0), + fontWeight: FontWeight.bold, + ), + ), ), ), - ), - ), - ], + ], + ); + }, ), ); } @@ -793,9 +802,8 @@ class _UnionDetailsPage extends State { ? activitys[position].coverImg : "", aspectRatio: 2.2, - radius: BorderRadius.only( - topRight: Radius.circular(8), - topLeft: Radius.circular(8), + radius: BorderRadius.vertical( + top: Radius.circular(8), ), fit: BoxFit.cover, errorSrc: "assets/image/default_2_1.png", @@ -911,26 +919,12 @@ class _UnionDetailsPage extends State { ); } -//{"uid":"1412687522458238976", -// "userInfo":{"headimg":"https:\/\/pos.upload.gznl.top\/admin\/2021\/07\/4ed055e5-5341-4080-a6f0-fe97c62d078f.jpg", -// "balance":null, -// "money":"0.00", -// "phone":"13800138000", -// "isBind":true, -// "nickname":"你这橘子洋气呀" -// }, -// "baseURL":"https:\/\/pos-test.api.lotus-wallet.com\/app\/", -// "shopId":"1344490596986781696", -// "tenantCode":"1177", -// "position":"30.554638,114.34394500000002", -// "token":"Bearer eyJ0eXAiOiJKc29uV2ViVG9rZW4iLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX3R5cGUiOiJNSU5JIiwibmFtZSI6IiIsInRva2VuX3R5cGUiOiJ0b2tlbiIsInVzZXJpZCI6IjE0MTI2ODc1MjI0NTgyMzg5NzYiLCJhY2NvdW50IjoiIiwiZXhwIjoxNjI2Nzk1Nzc0LCJuYmYiOjE2MjY3NjY5NzR9.cggcx_vqTozKS-z9uygjV4uA2yHQ4eWssMAngd2c-i0"} printMin() async { String miniAppId = storeInfo.mini.miniAppId; - print("print isExistsApp: ${await Min.isExistsApp(miniAppId)}"); - print("print getAppBasePath: ${await Min.getAppBasePath(miniAppId)}"); - print("print currentPageUrl: ${await Min.currentPageUrl()}"); - print("print runingAppid: ${await Min.runingAppid()}"); - // print("print getAppVersionInfo: ${await Min.getAppVersionInfo(miniAppId)}"); + debugPrint("print isExistsApp: ${await Min.isExistsApp(miniAppId)}"); + debugPrint("print getAppBasePath: ${await Min.getAppBasePath(miniAppId)}"); + debugPrint("print currentPageUrl: ${await Min.currentPageUrl()}"); + debugPrint("print runingAppid: ${await Min.runingAppid()}"); } _loginMin() async { @@ -1008,67 +1002,20 @@ class _UnionDetailsPage extends State { }); } - Function state; double progressValue = 0; String downText = "正在下载中..."; downloadWgt(appid, savePath) async { downText = S.of(context).zhengzaixiazaizhong; - showCupertinoDialog( - context: context, - barrierDismissible: true, - builder: (context) { - return Material( - type: MaterialType.transparency, - child: StatefulBuilder(builder: (context, status) { - state = status; - return Center( - child: Container( - width: 130.w, - height: 130.h, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(8), - color: Colors.white, - ), - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - SizedBox( - height: 40.h, - width: 40.w, - child: CircularProgressIndicator( - value: progressValue, - backgroundColor: Colors.yellow, - color: Colors.blue, - valueColor: AlwaysStoppedAnimation(Colors.red), - ), - ), - Text( - downText, - style: TextStyle( - color: Colors.black, - fontSize: 16.sp, - fontWeight: FontWeight.bold, - ), - ), - ], - ), - ), - ); - }), - ); - }); - Response response = await Dio() .download(storeInfo.mini.miniDownloadUrl, savePath, onReceiveProgress: (progress, max) { progressValue = progress.toDouble() / max.toDouble(); - // print("print progressValue: $progressValue"); - state(() {}); + EasyLoading.showProgress(progressValue, status: downText); }); if (response.statusCode == 200) { downText = "下载完成"; + EasyLoading.showProgress(progressValue, status: downText); SharedPreferences.getInstance().then((value) { value.setStringList( "miniAppid", @@ -1077,15 +1024,12 @@ class _UnionDetailsPage extends State { : []) ..add(appid)); }); - state(() {}); - Future.delayed(Duration(seconds: 1), () { - if (Navigator.canPop(context)) { - Navigator.of(context).pop(); - } - }); } else { print("print 下载失败"); } + Future.delayed(Duration(seconds: 1), () { + EasyLoading.dismiss(); + }); } List itemServer(String businessService) { @@ -1112,7 +1056,7 @@ class _UnionDetailsPage extends State { showCallMobile() { showCupertinoModalPopup( context: context, - builder: (contetx) { + builder: (context) { return CupertinoActionSheet( title: Text(S.of(context).bodadianhua), actions: [ diff --git a/lib/union/union_page.dart b/lib/union/union_page.dart index f593117b..23436668 100644 --- a/lib/union/union_page.dart +++ b/lib/union/union_page.dart @@ -7,6 +7,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart'; import 'package:flutter_baidu_mapapi_utils/flutter_baidu_mapapi_utils.dart'; +import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/main.dart'; @@ -34,8 +35,12 @@ class UnionPage extends StatefulWidget { class _UnionPage extends State with AutomaticKeepAliveClientMixin, WidgetsBindingObserver { - RefreshController refreshController = + + final RefreshController refreshController = RefreshController(initialRefresh: false); + ApiService apiService; + bool isKeyBoardShow = false; + BMFCoordinate latLng; @override void dispose() { @@ -46,8 +51,6 @@ class _UnionPage extends State refreshController.dispose(); } - bool isKeyBoardShow = false; - @override void didChangeMetrics() { super.didChangeMetrics(); @@ -67,18 +70,13 @@ class _UnionPage extends State }); } - ApiService apiService; - @override void initState() { super.initState(); WidgetsBinding.instance.addObserver(this); - Location.getInstance() - .aMapFlutterLocation - .onResultCallback() - .listen((event) { - print("value: "); + Location.getInstance().aMapFlutterLocation + .onResultCallback().listen((event) { if (event != null && event["latitude"] != null && event["longitude"] != null) { @@ -114,6 +112,8 @@ class _UnionPage extends State zoomLevel: 15, )); }); + } else { + EasyLoading.dismiss(); } }); @@ -126,13 +126,19 @@ class _UnionPage extends State getLatLng(); Location.getInstance().prepareLoc(); + startLocation(); + } + + startLocation() async { + EasyLoading.show(status: S.current.zhengzaijiazai); Location.getInstance().startLocation(context).then((value) { - refreshController.refreshCompleted(); + if (!value) { + EasyLoading.dismiss(); + refreshController.refreshCompleted(); + } }); } - BMFCoordinate latLng; - saveLatLng(BMFCoordinate latLng, province, city, district) async { SharedPreferences prefs = await SharedPreferences.getInstance(); await prefs.setString("latitude", "${latLng.latitude}"); @@ -195,11 +201,11 @@ class _UnionPage extends State }).catchError((error) { refreshController.refreshFailed(); }); - SmartDialog.dismiss(); + EasyLoading.dismiss(); if (baseData != null && baseData.isSuccess) { storeList = baseData.data; refreshController.refreshCompleted(); - if (mounted) setState(() {}); + setState(() {}); } else { refreshController.refreshFailed(); } @@ -250,11 +256,7 @@ class _UnionPage extends State physics: BouncingScrollPhysics(), header: MyHeader(), onRefresh: () { - print( - "object: ${Location.getInstance().aMapFlutterLocation == null}"); - Location.getInstance().startLocation(context).then((value) { - refreshController.refreshCompleted(); - }); + startLocation(); }, child: ListView.builder( itemCount: storeList == null ? 0 : storeList.length, @@ -265,8 +267,12 @@ class _UnionPage extends State itemBuilder: (context, position) { return GestureDetector( onTap: () { - Navigator.of(context).pushNamed('/router/union_detail_page', - arguments: {"id": storeList[position].id}); + Navigator.of(context).pushNamed( + '/router/union_detail_page', + arguments: { + "id": storeList[position].id, + "storeName": storeList[position].storeName + }); }, child: buildStoreItem(storeList[position], position), ); @@ -276,7 +282,7 @@ class _UnionPage extends State } BMFMapController _mapController; - TextEditingController editingController = TextEditingController(); + final TextEditingController editingController = TextEditingController(); void onMapCreated(BMFMapController controller) { _mapController = controller; @@ -302,9 +308,7 @@ class _UnionPage extends State child: TextField( textInputAction: TextInputAction.search, onEditingComplete: () { - Location.getInstance().startLocation(context).then((value) { - refreshController.refreshCompleted(); - }); + startLocation(); }, controller: editingController, cursorHeight: 30.h, diff --git a/lib/utils/location.dart b/lib/utils/location.dart index 3d237e58..70e6eda7 100644 --- a/lib/utils/location.dart +++ b/lib/utils/location.dart @@ -48,17 +48,20 @@ class Location { }); } - Future startLocation(context) async { + Future startLocation(context) async { if (!(await Permission.locationWhenInUse.serviceStatus.isEnabled)) { enableLocation(context); - return; + return false; } if (await Permission.location.isPermanentlyDenied) { requestDialog(context); + return false; } else if (await Permission.location.isGranted) { aMapFlutterLocation.startLocation(); + return true; } else if (await Permission.location.isUndetermined) { await Permission.location.request(); + return false; } else { if (Platform.isIOS) { //去设置中心 @@ -66,6 +69,7 @@ class Location { } else { await Permission.location.request(); } + return false; } } diff --git a/lib/view_widget/classic_header.dart b/lib/view_widget/classic_header.dart index 2dafad97..6cca75ff 100644 --- a/lib/view_widget/classic_header.dart +++ b/lib/view_widget/classic_header.dart @@ -7,30 +7,33 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart' hide RefreshIndicator, RefreshIndicatorState; import 'package:flutter/services.dart'; +import 'package:flutter_spinkit/flutter_spinkit.dart'; import 'package:huixiang/generated/l10n.dart'; -import 'package:huixiang/view_widget/rotate_container.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:rive/rive.dart'; class MyHeader extends StatelessWidget { @override Widget build(BuildContext context) { - // return CustomHeader(); return MyClassicHeader( - completeIcon: const Icon(Icons.done, color: Color(0xFF32A060)), + refreshStyle: RefreshStyle.Follow, completeText: S.of(context).shuaxinchenggong, failedText: S.of(context).shuaxinshibai, refreshingText: S.of(context).shuaxinzhong, releaseText: S.of(context).shifangshuaxin, idleText: S.of(context).xialashuaxin, - completeTextStyle: TextStyle(color: Color(0xFF32A060)), - refreshingIcon: RotateContainer( - rotated: true, - child: Image.asset( - "assets/image/icon_header_loading.png", - width: 24, - height: 24, - ), + iconPos: IconPosition.left, + completeTextStyle: TextStyle( + color: Color(0xFF32A060), + ), + completeIcon: Icon( + Icons.done, + color: Color(0xFF32A060), + ), + refreshingIcon: SpinKitCircle( + color: Colors.grey, + size: 24.w, ), ); } @@ -44,14 +47,11 @@ class CustomHeader extends RefreshIndicator { } class _CustomHeader extends RefreshIndicatorState { - FlareControls flareController = FlareControls(); Artboard _riveArtboard; RiveAnimationController _controllerIdle; - - @override void initState() { super.initState(); @@ -72,7 +72,6 @@ class _CustomHeader extends RefreshIndicatorState { @override Widget buildContent(BuildContext context, RefreshStatus mode) { - if (_controllerIdle != null) { if (mode == RefreshStatus.idle) { _controllerIdle.isActive = false; @@ -213,21 +212,29 @@ class _ClassicHeaderState extends RefreshIndicatorState { Widget buildContent(BuildContext context, RefreshStatus mode) { Widget textWidget = _buildText(mode); Widget iconWidget = _buildIcon(mode); - List children = [iconWidget, textWidget]; - final Widget container = Wrap( - spacing: widget.spacing, - textDirection: widget.iconPos == IconPosition.left - ? TextDirection.ltr - : TextDirection.rtl, - direction: widget.iconPos == IconPosition.bottom || - widget.iconPos == IconPosition.top - ? Axis.vertical - : Axis.horizontal, - crossAxisAlignment: WrapCrossAlignment.center, - verticalDirection: widget.iconPos == IconPosition.bottom - ? VerticalDirection.up - : VerticalDirection.down, - alignment: WrapAlignment.center, + List children = [ + iconWidget, + SizedBox( + width: 10, + ), + textWidget + ]; + final Widget container = Row( + // spacing: widget.spacing, + // textDirection: widget.iconPos == IconPosition.left + // ? TextDirection.ltr + // : TextDirection.rtl, + // direction: widget.iconPos == IconPosition.bottom || + // widget.iconPos == IconPosition.top + // ? Axis.vertical + // : Axis.horizontal, + // crossAxisAlignment: WrapCrossAlignment.center, + // verticalDirection: widget.iconPos == IconPosition.bottom + // ? VerticalDirection.up + // : VerticalDirection.down, + // alignment: WrapAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, children: children, ); return widget.outerBuilder != null diff --git a/pubspec.lock b/pubspec.lock index fd64c12c..31ea9fb7 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -328,6 +328,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.1.3" + flutter_easyloading: + dependency: "direct main" + description: + name: flutter_easyloading + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.0.0" flutter_html: dependency: "direct main" description: @@ -375,6 +382,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.1.6" + flutter_spinkit: + dependency: "direct main" + description: + name: flutter_spinkit + url: "https://pub.flutter-io.cn" + source: hosted + version: "5.0.0" flutter_staggered_grid_view: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 6741f350..a3a4639d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -86,6 +86,9 @@ dependencies: sharesdk_plugin: ^1.3.0 + flutter_spinkit: ^5.0.0 + flutter_easyloading: ^3.0.0 + rive: ^0.6.8 flare_flutter: ^3.0.2