From 7ab83047cdef01734239bd795262640243e96c76 Mon Sep 17 00:00:00 2001 From: fmk Date: Sat, 9 Oct 2021 17:44:33 +0800 Subject: [PATCH 1/4] safety --- lib/main.dart | 2 + lib/store/store_order.dart | 103 ++++++++++++++------- lib/store/store_view/store_order_list.dart | 29 ++++-- lib/test_page.dart | 81 ++++++++++++++++ pubspec.lock | 12 +-- pubspec.yaml | 4 +- 6 files changed, 186 insertions(+), 45 deletions(-) create mode 100644 lib/test_page.dart diff --git a/lib/main.dart b/lib/main.dart index da62d3d6..d7ff1d43 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -55,6 +55,7 @@ import 'package:huixiang/setting/treaty_page.dart'; // import 'package:huixiang/store/settlement.dart'; import 'package:huixiang/store/store_order.dart'; import 'package:huixiang/store/store_view/settlement.dart'; +import 'package:huixiang/test_page.dart'; import 'package:huixiang/union/location_map_page.dart'; import 'package:huixiang/web/web_page.dart'; @@ -264,5 +265,6 @@ Map routers = { '/router/about_page': (context, {arguments}) => AboutPage(), '/router/qr_share': (context, {arguments}) => QrSharePage(), '/router/main_page': (context, {arguments}) => MainPage(), + '/router/test_page': (context, {arguments}) => TestPage(), // '/router/ui_test': (context, {arguments}) => UITest(), }; diff --git a/lib/store/store_order.dart b/lib/store/store_order.dart index bbe9a348..8257b5ce 100644 --- a/lib/store/store_order.dart +++ b/lib/store/store_order.dart @@ -44,6 +44,8 @@ class _StoreOrderPage extends State RefreshController refreshController; List _widgetOptions; + ScrollController controller = ScrollController(); + @override void initState() { super.initState(); @@ -70,14 +72,16 @@ class _StoreOrderPage extends State /// 小程序登录 minLogin() { - apiService.minLogin(widget.arguments["id"]) - .catchError((onError){}).then((baseData) { + apiService + .minLogin(widget.arguments["id"]) + .catchError((onError) {}) + .then((baseData) { if (baseData != null && baseData.isSuccess) { UserEntity userEntity = UserEntity.fromJson(baseData.data); String minToken = userEntity.token; SharedPreferences.getInstance().then((value) => { - value.setString('minToken', minToken), - }); + value.setString('minToken', minToken), + }); minService = MinApiService( Dio(), context: context, @@ -114,8 +118,6 @@ class _StoreOrderPage extends State } } - ScrollController controller = ScrollController(); - @override Widget build(BuildContext context) { return Stack( @@ -146,16 +148,6 @@ class _StoreOrderPage extends State SliverOverlapAbsorber( handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context), sliver: SliverAppBar( - title: Text( - storeInfo != null - ? storeInfo.storeName - : '', - style: TextStyle( - color: Colors.black, - fontWeight: FontWeight.bold, - fontSize: 18.sp, - ), - ), expandedHeight: (storeInfo != null && storeInfo.couponVOList != null) ? 425.h @@ -164,10 +156,6 @@ class _StoreOrderPage extends State snap: false, pinned: true, stretch: false, - onStretchTrigger: () { - return Future.sync((){}); - }, - stretchTriggerOffset: 100, leading: GestureDetector( onTap: () { Navigator.of(context).pop(); @@ -184,17 +172,10 @@ class _StoreOrderPage extends State ), ), flexibleSpace: FlexibleSpaceBar( - // title: Container( - // margin: EdgeInsets.only(bottom: 40), - // child: Text( - // 'Expanded Title', - // style: TextStyle( - // color: Colors.black, - // fontWeight: FontWeight.bold, - // fontSize: 18.sp, - // ), - // ), - // ), + title: Title( + controller, + storeInfo != null ? storeInfo.storeName : '', + ), collapseMode: CollapseMode.pin, stretchModes: [ StretchMode.zoomBackground, @@ -264,7 +245,7 @@ class _StoreOrderPage extends State bottom: PreferredSize( preferredSize: Size( MediaQuery.of(context).size.width, - 38.h, + 38, ), child: Container( padding: EdgeInsets.symmetric(horizontal: 10.w), @@ -540,6 +521,10 @@ class _StoreOrderPage extends State backgroup: Color(0xFF32A060), fontSize: 12.sp, radius: 100, + callback: () { + Navigator.of(context) + .pushNamed('/router/test_page'); + }, ), ), ], @@ -670,3 +655,57 @@ class _StoreOrderPage extends State // @override // bool get wantKeepAlive => true; } + +class Title extends StatefulWidget { + final ScrollController controller; + final String title; + + Title(this.controller, this.title); + + @override + State createState() { + return _Title(); + } +} + +class _Title extends State { + double alpha = 0; + + @override + void initState() { + super.initState(); + + widget.controller.addListener(() { + double maxScrollExtent = widget.controller.position.maxScrollExtent; + double alphaHeight = (kToolbarHeight) / 2; + double alphaProgress = maxScrollExtent - widget.controller.offset; + double alphatemp = 0; + if (alphaProgress <= 1) { + alphatemp = 1; + } else if (alphaProgress <= alphaHeight) { + alphatemp = (((alphaHeight - alphaProgress) / alphaHeight) > 0.5) ? 1 : 0; + } else { + alphatemp = 0; + } + if (alpha != alphatemp && mounted) { + alpha = alphatemp; + setState(() {}); + } + }); + } + + @override + Widget build(BuildContext context) { + return Container( + margin: EdgeInsets.only(bottom: 38), + child: Text( + widget.title ?? "", + style: TextStyle( + color: Colors.black.withOpacity(alpha), + fontWeight: FontWeight.bold, + fontSize: 18.sp, + ), + ), + ); + } +} diff --git a/lib/store/store_view/store_order_list.dart b/lib/store/store_view/store_order_list.dart index 6f5e134d..88392dd7 100644 --- a/lib/store/store_view/store_order_list.dart +++ b/lib/store/store_view/store_order_list.dart @@ -45,11 +45,31 @@ class _StoreOrderListPage extends State<StoreOrderListPage> { int isChoice = 0; int tempClickIndex = 0; + ScrollController controller1 = ScrollController(); + ScrollController controller2 = ScrollController(); + + bool scrollEnable = false; + @override void initState() { super.initState(); - widget.controller.addListener(() {}); + // widget.controller.addListener(() { + // double maxScrollExtent = widget.controller.position.maxScrollExtent; + // bool scrollEnableTemp ; + // if (mounted) { + // if ((maxScrollExtent - widget.controller.offset) == 0) { + // scrollEnableTemp = true; + // } else { + // scrollEnableTemp = false; + // } + // if (scrollEnableTemp != scrollEnable) { + // scrollEnable = scrollEnableTemp; + // setState(() {}); + // } + // } + // }); + } @override @@ -67,7 +87,7 @@ class _StoreOrderListPage extends State<StoreOrderListPage> { child: ListView.builder( itemCount: 28, padding: EdgeInsets.only(top: 25, bottom: 50), - controller: widget.controller, + controller: controller1, itemBuilder: (context, position) { return orderItem(position); }, @@ -78,7 +98,7 @@ class _StoreOrderListPage extends State<StoreOrderListPage> { child: ListView.builder( itemCount: 15, padding: EdgeInsets.only(top: 25, bottom: 50), - // controller: widget.controller, + // controller: controller2, itemBuilder: (context, position) { return goodsItem(); }, @@ -89,9 +109,6 @@ class _StoreOrderListPage extends State<StoreOrderListPage> { ); } - ScrollController controller1 = ScrollController(); - ScrollController controller2 = ScrollController(); - Widget orderItem(int index) { return Container( child: Column( diff --git a/lib/test_page.dart b/lib/test_page.dart new file mode 100644 index 00000000..662e52f8 --- /dev/null +++ b/lib/test_page.dart @@ -0,0 +1,81 @@ + +import 'package:flutter/material.dart'; + + +class TestPage extends StatefulWidget { + @override + State<StatefulWidget> createState() { + return _TestPage(); + } +} + +class _TestPage extends State<TestPage> { + // ZefyrController controller = ZefyrController(NotusDocument.fromDelta(null)); + // FocusNode focusNode = FocusNode(); + + @override + Widget build(BuildContext context) { + // 改变样式 + // final theme = ZefyrThemeData( + // toolbarTheme: ToolbarTheme.fallback(context), + // ); + + return Scaffold( + // resizeToAvoidBottomInset: true, + // appBar: AppBar( + // elevation: 1.0, + // backgroundColor: Colors.grey.shade200, + // brightness: Brightness.light, + // title: Text("data"), + // ), + // body: ZefyrScaffold( + // child: ZefyrTheme( + // data: theme, + // child: ZefyrEditor( + // controller: controller, + // focusNode: focusNode, + // imageDelegate: CustomImageDelegate(), + // ), + // ), + // ), + ); + } +} + +// class CustomImageDelegate implements ZefyrImageDelegate<String> { +// String url = ""; +// +// @override +// Future<String> pickImage(String source) async { +// // final file = await ImagePicker.pickImage(source: source); +// // if (file == null) return null; +// // // Use my storage service to upload selected file. The uploadImage method +// // // returns unique ID of newly uploaded image on my server. +// // +// // // 这里是我的后端地址(你们可以写自己的后台地址 +// // var request = await requestfile("url",file, null); +// // print(request); +// // if(request["code"] == "200") { +// // print("图片上传成功"); +// // } else { +// // print("图片上传失败"); +// // } +// // url = "$SERVER_URL/static/articlePictre/${request["data"]}"; +// return url; +// } +// +// @override +// Widget buildImage(BuildContext context, String imageSource) { +// // We use custom "asset" scheme to distinguish asset images from other files. +// print("imageSource is $imageSource"); +// // 这里拿到刚才return url 也就是 delta 的文本内容,不可以使用上面的url,直接 imageSource 就可以 +// return Image.network(imageSource); +// } +// +// @override +// String get cameraSource => url; +// +// @override +// String get gallerySource => url; +// +// } diff --git a/pubspec.lock b/pubspec.lock index 018bdc0d..b3ffae43 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -986,42 +986,42 @@ packages: name: url_launcher url: "https://pub.flutter-io.cn" source: hosted - version: "6.0.5" + version: "5.7.10" url_launcher_linux: dependency: transitive description: name: url_launcher_linux url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.2" + version: "0.0.1+4" url_launcher_macos: dependency: transitive description: name: url_launcher_macos url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.2" + version: "0.0.1+9" url_launcher_platform_interface: dependency: transitive description: name: url_launcher_platform_interface url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.1" + version: "1.0.9" url_launcher_web: dependency: transitive description: name: url_launcher_web url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.4" + version: "0.1.5+3" url_launcher_windows: dependency: transitive description: name: url_launcher_windows url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.2" + version: "0.0.1+3" uuid: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 6d3d1331..9feb7e27 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -56,7 +56,7 @@ dependencies: barcode_widget: ^2.0.1 flutter_qr_reader: ^1.0.5 qr_flutter: ^4.0.0 - url_launcher: ^6.0.5 + url_launcher: ^5.0.0 image_cropper: ^1.4.1 image_picker_gallery_camera: ^0.1.6 @@ -87,6 +87,8 @@ dependencies: # flutter_bugly: ^0.3.3 # bitmap: ^0.1.2 +# zefyr: ^0.12.0 + dev_dependencies: flutter_test: sdk: flutter From 7d299d9ca9fe63b85f4e81427d0e58d4a2bdcfe1 Mon Sep 17 00:00:00 2001 From: fmk <fengmeikan@hotmail.com> Date: Sat, 9 Oct 2021 18:27:12 +0800 Subject: [PATCH 2/4] safety --- lib/store/store_view/store_order_list.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/store/store_view/store_order_list.dart b/lib/store/store_view/store_order_list.dart index 88392dd7..fe81aed4 100644 --- a/lib/store/store_view/store_order_list.dart +++ b/lib/store/store_view/store_order_list.dart @@ -207,6 +207,7 @@ class _StoreOrderListPage extends State<StoreOrderListPage> { fontWeight: MyFontWeight.medium, ), ), + SizedBox(width: 4), Text( "¥19.00", style: TextStyle( @@ -217,6 +218,7 @@ class _StoreOrderListPage extends State<StoreOrderListPage> { ), ], ), + SizedBox(height: 2), Row( children: [ Text( @@ -227,7 +229,7 @@ class _StoreOrderListPage extends State<StoreOrderListPage> { fontWeight: MyFontWeight.regular, ), ), - SizedBox(width: 10), + SizedBox(width: 2), Text( "¥19.00", style: TextStyle( From b4658c7005d805ab8ff0908fa5e17ed827dbcfc5 Mon Sep 17 00:00:00 2001 From: fmk <fengmeikan@hotmail.com> Date: Mon, 11 Oct 2021 15:01:48 +0800 Subject: [PATCH 3/4] safety --- lib/store/store_view/store_order_list.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/store/store_view/store_order_list.dart b/lib/store/store_view/store_order_list.dart index fe81aed4..e66526ea 100644 --- a/lib/store/store_view/store_order_list.dart +++ b/lib/store/store_view/store_order_list.dart @@ -188,7 +188,7 @@ class _StoreOrderListPage extends State<StoreOrderListPage> { fontSize: 10.sp, fontWeight: MyFontWeight.regular, ), - ) + ), ], ), SizedBox(height: 7), @@ -365,6 +365,7 @@ class _StoreOrderListPage extends State<StoreOrderListPage> { fontWeight: MyFontWeight.medium, ), ), + SizedBox(width: 4), Text( "¥19.00", style: TextStyle( From cb9a6a91ba544e027685ca7c26ff7a526f2d5a84 Mon Sep 17 00:00:00 2001 From: fmk <fengmeikan@hotmail.com> Date: Mon, 11 Oct 2021 16:20:19 +0800 Subject: [PATCH 4/4] safety --- lib/retrofit/data/findMiNiGroupList.dart | 6 ++--- lib/retrofit/min_api.dart | 12 ++++++--- lib/retrofit/retrofit_api.dart | 8 +++--- lib/store/store_order.dart | 30 +++------------------- lib/store/store_view/store_order_list.dart | 16 +++++++----- lib/union/union_page.dart | 1 + 6 files changed, 30 insertions(+), 43 deletions(-) diff --git a/lib/retrofit/data/findMiNiGroupList.dart b/lib/retrofit/data/findMiNiGroupList.dart index e41b2a90..5f2716c1 100644 --- a/lib/retrofit/data/findMiNiGroupList.dart +++ b/lib/retrofit/data/findMiNiGroupList.dart @@ -15,7 +15,7 @@ class FindMiNiGroupList { List<ProductListBean> productList; dynamic productPageVO; - static FindMiNiGroupList fromMap(Map<String, dynamic> map) { + static FindMiNiGroupList fromJson(Map<String, dynamic> map) { if (map == null) return null; FindMiNiGroupList findMiNiGroupListBean = FindMiNiGroupList(); findMiNiGroupListBean.id = map['id']; @@ -24,7 +24,7 @@ class FindMiNiGroupList { findMiNiGroupListBean.groupImg = map['groupImg']; findMiNiGroupListBean.sort = map['sort']; findMiNiGroupListBean.productList = List()..addAll( - (map['productList'] as List ?? []).map((o) => ProductListBean.fromMap(o)) + (map['productList'] as List ?? []).map((o) => ProductListBean.fromJson(o)) ); findMiNiGroupListBean.productPageVO = map['productPageVO']; return findMiNiGroupListBean; @@ -100,7 +100,7 @@ class ProductListBean { String printerFlag; dynamic markProductNone; - static ProductListBean fromMap(Map<String, dynamic> map) { + static ProductListBean fromJson(Map<String, dynamic> map) { if (map == null) return null; ProductListBean productListBean = ProductListBean(); productListBean.id = map['id']; diff --git a/lib/retrofit/min_api.dart b/lib/retrofit/min_api.dart index 3d91dc41..1f0279cf 100644 --- a/lib/retrofit/min_api.dart +++ b/lib/retrofit/min_api.dart @@ -18,8 +18,8 @@ part 'min_api.g.dart'; // const base_url = "https://pos.platform.lotus-wallet.com/app/"; ///正式 // const baseUrl = "https://pos.platform.lotus-wallet.com/app/"; ///正式 -const base_url = "http://192.168.10.236:8766/app/"; ///费韬 -const baseUrl = "http://192.168.10.236:8766/app/"; ///费韬 +const base_url = "http://192.168.10.236:8765/app/"; ///费韬 +const baseUrl = "http://192.168.10.236:8765/app/"; ///费韬 // const base_url = "http://192.168.10.37:8766/app/"; // const baseUrl = "http://192.168.10.37:8766/app/"; @@ -31,17 +31,21 @@ abstract class MinApiService { String baseUrl, BuildContext context, String token, + String tenant, bool showLoading = true, bool pay = false, }) { Map<String, dynamic> headers = (token == null || token == "") ? {} : {'token': "Bearer $token"}; + if (tenant != null && tenant != "") { + headers["tenant"] = tenant; + } if (pay) { headers["Environment"] = "app"; } dio.options = BaseOptions( - connectTimeout: 60000, - receiveTimeout: 60000, + connectTimeout: 10000, + receiveTimeout: 10000, headers: headers, responseType: ResponseType.json, ); diff --git a/lib/retrofit/retrofit_api.dart b/lib/retrofit/retrofit_api.dart index 47280305..c804a5b2 100644 --- a/lib/retrofit/retrofit_api.dart +++ b/lib/retrofit/retrofit_api.dart @@ -37,11 +37,11 @@ import 'data/wx_pay.dart'; part 'retrofit_api.g.dart'; -const base_url = "https://pos.platform.lotus-wallet.com/app/"; ///正式 -const baseUrl = "https://pos.platform.lotus-wallet.com/app/"; ///正式 +// const base_url = "https://pos.platform.lotus-wallet.com/app/"; ///正式 +// const baseUrl = "https://pos.platform.lotus-wallet.com/app/"; ///正式 -// const base_url = "http://192.168.10.236:8766/app/"; ///费韬 -// const baseUrl = "http://192.168.10.236:8766/app/"; ///费韬 +const base_url = "http://192.168.10.236:8766/app/"; ///费韬 +const baseUrl = "http://192.168.10.236:8766/app/"; ///费韬 // const base_url = "http://192.168.10.37:8766/app/"; // const baseUrl = "http://192.168.10.37:8766/app/"; diff --git a/lib/store/store_order.dart b/lib/store/store_order.dart index 56a6e9f3..7d4d4566 100644 --- a/lib/store/store_order.dart +++ b/lib/store/store_order.dart @@ -8,6 +8,7 @@ import 'package:huixiang/retrofit/data/activity.dart'; import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/retrofit/data/order_info.dart'; import 'package:huixiang/retrofit/data/store_info.dart'; +import 'package:huixiang/retrofit/data/user_entity.dart'; import 'package:huixiang/retrofit/min_api.dart'; import 'package:huixiang/retrofit/retrofit_api.dart'; import 'package:huixiang/store/store_view/store_activity.dart'; @@ -63,7 +64,6 @@ class _StoreOrderPage extends State<StoreOrderPage> StoreOrderListPage( widget.arguments, widget.activitys, storeInfo, controller), - ///星店活动, StoreActivity( widget.arguments, @@ -74,27 +74,6 @@ class _StoreOrderPage extends State<StoreOrderPage> queryStoreInfo(); } - /// 小程序登录 - minLogin() { - apiService - .minLogin(widget.arguments["id"]) - .catchError((onError) {}) - .then((baseData) { - if (baseData != null && baseData.isSuccess) { - UserEntity userEntity = UserEntity.fromJson(baseData.data); - String minToken = userEntity.token; - SharedPreferences.getInstance().then((value) => { - value.setString('minToken', minToken), - }); - minService = MinApiService( - Dio(), - context: context, - token: minToken, - ); - } - }); - } - /// 查询店铺信息 queryStoreInfo() async { final SharedPreferences value = await SharedPreferences.getInstance(); @@ -104,8 +83,6 @@ class _StoreOrderPage extends State<StoreOrderPage> token: value.getString('token'), ); - minLogin(); - BaseData baseData = await apiService .queryStoreInfo(widget.arguments["id"]) .catchError((error) { @@ -243,7 +220,7 @@ class _StoreOrderPage extends State<StoreOrderPage> ], ), ), - backgroundColor: Color(0xFFFAFAFA), + backgroundColor: Color(0x33FAFAFA), centerTitle: false, elevation: 0, bottom: PreferredSize( @@ -548,7 +525,7 @@ class _StoreOrderPage extends State<StoreOrderPage> ); } - Widget shoppGoodsItem() { + Widget shoppGoodsItem(ProductList pro, position) { return Container( padding: EdgeInsets.only(bottom: 10), child: Row( @@ -698,6 +675,7 @@ class _Title extends State<Title> { } if (alpha != alphatemp && mounted) { alpha = alphatemp; + print("object: $alpha"); setState(() {}); } }); diff --git a/lib/store/store_view/store_order_list.dart b/lib/store/store_view/store_order_list.dart index 29fc3454..b1d9f1e9 100644 --- a/lib/store/store_view/store_order_list.dart +++ b/lib/store/store_view/store_order_list.dart @@ -79,15 +79,18 @@ class _StoreOrderListPage extends State<StoreOrderListPage> { apiService.minLogin(widget.arguments["id"]) .catchError((onError){}).then((baseData) { if (baseData != null && baseData.isSuccess) { - UserEntity userEntity = UserEntity.fromJson(baseData.data); - String minToken = userEntity.token; + Map<String, dynamic> minStoreInfo = baseData.data; + String minToken = minStoreInfo["token"]; + String tenant = widget.arguments["tenant"]; SharedPreferences.getInstance().then((value) => { value.setString('minToken', minToken), + value.setString('tenant', tenant), }); minService = MinApiService( Dio(), context: context, token: minToken, + tenant: tenant, ); appletGoods(); } @@ -115,17 +118,18 @@ class _StoreOrderListPage extends State<StoreOrderListPage> { Widget build(BuildContext context) { return Container( width: MediaQuery.of(context).size.width, - height: MediaQuery.of(context).size.height, + height: MediaQuery.of(context).size.height - (kToolbarHeight + 38 + 54.h), + margin: EdgeInsets.only(top: (MediaQuery.of(context).padding.top + 38 + kToolbarHeight)), child: Row( mainAxisAlignment: MainAxisAlignment.start, mainAxisSize: MainAxisSize.max, children: [ Container( width: 100.w, - height: MediaQuery.of(context).size.height, child: ListView.builder( itemCount: appletProducts == null ? 0 : appletProducts.length, - controller: widget.controller, + controller: controller1, + padding: EdgeInsets.zero, itemBuilder: (context, position) { return orderItem(appletProducts[position],position); }, @@ -136,6 +140,7 @@ class _StoreOrderListPage extends State<StoreOrderListPage> { child: ListView.builder( itemCount: productListBeans == null ? 0 : productListBeans.length, // controller: widget.controller, + padding: EdgeInsets.zero, itemBuilder: (context, position) { return goodsItem(productListBeans[position], position); }, @@ -151,7 +156,6 @@ class _StoreOrderListPage extends State<StoreOrderListPage> { Widget orderItem(FindMiNiGroupList findMiNiGroupList,int index) { return Container( - padding: EdgeInsets.only(top:100.h), child: Column( mainAxisAlignment: MainAxisAlignment.spaceAround, crossAxisAlignment: CrossAxisAlignment.center, diff --git a/lib/union/union_page.dart b/lib/union/union_page.dart index 0cd45c2d..a2de2af8 100644 --- a/lib/union/union_page.dart +++ b/lib/union/union_page.dart @@ -279,6 +279,7 @@ class _UnionPage extends State<UnionPage> '/router/store_order', arguments: { "id": storeList[position].id, + "tenant": storeList[position].tenantCode, "storeName": storeList[position].storeName }, );