From 885ae63bbf08bc4fc5ff1ee07003027bb111f48f Mon Sep 17 00:00:00 2001 From: Weller <1812208341@qq.com> Date: Sun, 27 Sep 2020 19:24:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=95=86=E5=93=81=E5=88=86?= =?UTF-8?q?=E4=BA=AB=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dart_tool/package_config.json | 8 +- lib/pages/favorite_page.dart | 59 ++++ lib/pages/launch_page/launch_page.dart | 6 +- lib/register.dart | 2 + .../goods_share_template.dart | 286 ++++++++++++++++++ pubspec.yaml | 1 + 6 files changed, 357 insertions(+), 5 deletions(-) create mode 100644 lib/pages/favorite_page.dart create mode 100644 lib/template/goods_share_template/goods_share_template.dart diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json index cf9c2fa..d01ffc7 100644 --- a/.dart_tool/package_config.json +++ b/.dart_tool/package_config.json @@ -235,6 +235,12 @@ "packageUri": "lib/", "languageVersion": "1.20" }, + { + "name": "image_gallery_saver", + "rootUri": "file:///Users/fnuser/.pub-cache/hosted/pub.flutter-io.cn/image_gallery_saver-1.5.0", + "packageUri": "lib/", + "languageVersion": "2.1" + }, { "name": "image_picker", "rootUri": "file:///Users/fnuser/.pub-cache/hosted/pub.flutter-io.cn/image_picker-0.6.7+11", @@ -578,7 +584,7 @@ "languageVersion": "2.1" } ], - "generated": "2020-09-27T08:39:36.051865Z", + "generated": "2020-09-27T11:21:02.505016Z", "generator": "pub", "generatorVersion": "2.7.2" } diff --git a/lib/pages/favorite_page.dart b/lib/pages/favorite_page.dart new file mode 100644 index 0000000..c7bf497 --- /dev/null +++ b/lib/pages/favorite_page.dart @@ -0,0 +1,59 @@ +import 'dart:typed_data'; + +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:zhiying_base_widget/template/goods_share_template/goods_share_template.dart'; + +import 'package:image_gallery_saver/image_gallery_saver.dart'; + +class FavoritePage extends StatefulWidget { + @override + _FavoritePageState createState() => _FavoritePageState(); +} + +class _FavoritePageState extends State { + GlobalKey globalKey = GlobalKey(); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text('收藏夹'), + ), + body: Column( + children: [ + Container( + width: 100, + height: 200, + child: Transform.scale( + scale: 0.2, child: GoodsShareTemplate(key: globalKey)), + ), + FlatButton( + child: Icon(Icons.add), + onPressed: () async { + BuildContext buildContext = globalKey.currentContext; + + if (null != buildContext) { + RenderRepaintBoundary boundary = + buildContext.findRenderObject(); + var image = await boundary.toImage(); + ByteData byteData = + await image.toByteData(format: ui.ImageByteFormat.png); + // final result = await ImageGallerySaver.saveImage( + // byteData.buffer.asUint8List()); + // var response = await Dio().get( + // "https://ss0.baidu.com/94o3dSag_xI4khGko9WTAnF6hhy/image/h%3D300/sign=a62e824376d98d1069d40a31113eb807/838ba61ea8d3fd1fc9c7b6853a4e251f94ca5f46.jpg", + // options: Options(responseType: ResponseType.bytes)); + // final result = await ImageGallerySaver.saveImage( + // Uint8List.fromList(image), + // quality: 60, + // name: "hello"); + // print(result); + } + }, + ) + ], + ), + ); + } +} diff --git a/lib/pages/launch_page/launch_page.dart b/lib/pages/launch_page/launch_page.dart index c8aa453..56bfd6b 100644 --- a/lib/pages/launch_page/launch_page.dart +++ b/lib/pages/launch_page/launch_page.dart @@ -1,8 +1,8 @@ +import 'package:connectivity/connectivity.dart'; import 'package:flutter/material.dart'; import 'package:zhiying_base_widget/pages/home_page/home_page.dart'; import 'package:zhiying_comm/util/application.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; -import 'package:connectivity/connectivity.dart'; // 启动页,页面初始化等操作~跟原生启动页保持一致,防止白屏问题 class LaunchPage extends StatefulWidget { @@ -35,16 +35,14 @@ class _LaunchPageState extends State { Logger.error(err); }); } else { - Logger.debug('unknow'); + Logger.error('未知网络,APP初始化失败'); print('unknow'); } }); - super.initState(); } - @override Widget build(BuildContext context) { return Scaffold( diff --git a/lib/register.dart b/lib/register.dart index f7711af..2610e7f 100644 --- a/lib/register.dart +++ b/lib/register.dart @@ -1,3 +1,4 @@ +import 'package:zhiying_base_widget/pages/favorite_page.dart'; import 'package:zhiying_base_widget/pages/goods_details_page/goods_details_page.dart'; import 'package:zhiying_base_widget/pages/invited_friends/invited_friends.dart'; import 'package:zhiying_base_widget/pages/launch_page/launch_page.dart'; @@ -97,6 +98,7 @@ class BaseWidgetRegister { // 邀请好友 PageFactory.regist( 'pub.flutter.invite_friends', (model) => InvitedFriendsPage(model)); + PageFactory.regist('pub.flutter.fav', (model) => FavoritePage()); } // 注册控件 diff --git a/lib/template/goods_share_template/goods_share_template.dart b/lib/template/goods_share_template/goods_share_template.dart new file mode 100644 index 0000000..78a3d3d --- /dev/null +++ b/lib/template/goods_share_template/goods_share_template.dart @@ -0,0 +1,286 @@ +import 'package:flutter/material.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; + +// 商品详情分享,合成模板 +class GoodsShareTemplate extends StatelessWidget { + const GoodsShareTemplate({Key key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return OverflowBox( + maxHeight: double.infinity, + maxWidth: 375, + child: Container( + width: double.infinity, + padding: EdgeInsets.all(20), + color: Colors.white, + child: Column( + children: [ + _createHeader(), + _createImage(), + _createBottom(), + ], + ), + ), + ); + } + + Widget _createHeader() { + return Row( + children: [ + Container( + width: 30, + height: 30, + decoration: BoxDecoration( + color: Colors.redAccent, borderRadius: BorderRadius.circular(15)), + ), + Expanded( + child: Container( + margin: EdgeInsets.only(left: 10, right: 10), + height: 30, + width: 80, + color: Colors.redAccent, + ), + ), + Container( + padding: EdgeInsets.only(left: 10, right: 10, top: 8, bottom: 8), + decoration: BoxDecoration( + color: Color(0xfff7f7f7), + borderRadius: BorderRadius.circular(30)), + child: Text( + '邀请码 SDWE45', + style: TextStyle(fontSize: 11, fontWeight: FontWeight.bold), + ), + ) + ], + ); + } + + Widget _createImage() { + return AspectRatio( + aspectRatio: 1, + child: Container( + margin: EdgeInsets.only(top: 20, bottom: 20), + width: double.infinity, + color: Colors.redAccent, + ), + ); + } + + Widget _createBottom() { + return Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: Container( + margin: EdgeInsets.only(right: 20), + height: 160, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + _createTitle(), + Expanded( + child: Container(), + ), + _createLeftBottom() + ], + ), + ), + ), + Column( + children: [ + Container( + margin: EdgeInsets.only(bottom: 12), + width: 124, + height: 124, + color: Colors.redAccent, + ), + Container( + child: Row( + children: [ + Container( + width: 14, + height: 16, + color: Colors.redAccent, + margin: EdgeInsets.only(right: 4), + ), + Text( + '长按识别领取优惠', + style: TextStyle( + fontSize: 11, + color: Color(0xffb3b3b3), + ), + ), + ], + ), + ) + ], + ), + ], + ); + } + + Widget _createTitle() { + List list = List(); + list.add(WidgetSpan( + child: Container( + padding: EdgeInsets.only(left: 2, right: 2, top: 3, bottom: 3), + margin: EdgeInsets.only(right: 4), + child: Text( + '淘宝', + style: TextStyle( + fontSize: 9, + height: 1, + color: Colors.white, + ), + ), + decoration: BoxDecoration( + color: Colors.redAccent, borderRadius: BorderRadius.circular(2.5)), + ), + )); + list.add(TextSpan( + text: '小米10至尊纪念版5g手机120X变焦骁龙865小米官方旗舰店小米手机', + style: TextStyle( + fontSize: 14, + color: HexColor.fromHex('#333333'), + fontWeight: FontWeight.bold), + )); + return RichText( + maxLines: 3, + overflow: TextOverflow.ellipsis, + text: TextSpan(children: list), + ); + } + + Widget _createLeftBottom() { + return Row( + children: [ + Column( + children: [ + Container( + margin: EdgeInsets.only(right: 5), + padding: EdgeInsets.only(left: 10, right: 10, top: 3, bottom: 3), + decoration: BoxDecoration( + color: Colors.redAccent, + borderRadius: BorderRadius.circular(2.5), + ), + child: Text( + '到手价', + textAlign: TextAlign.center, + maxLines: 1, + style: TextStyle( + height: 1, + fontSize: 11, + color: HexColor.fromHex('#ffffff'), + ), + ), + ), + _createPrice(), + ], + ), + Expanded( + child: Container(), + ), + Column( + children: [ + Container( + margin: EdgeInsets.only(right: 5, bottom: 8), + padding: EdgeInsets.only(left: 10, right: 10, top: 3, bottom: 3), + decoration: BoxDecoration( + color: Colors.redAccent, + borderRadius: BorderRadius.circular(2.5), + ), + child: Text( + '700元券', + textAlign: TextAlign.center, + maxLines: 1, + style: TextStyle( + height: 1, + fontSize: 11, + color: HexColor.fromHex('#ffffff'), + ), + ), + ), + _createOriginPrice(), + ], + ), + ], + ); + } + + Widget _createOriginPrice() { + return Padding( + padding: EdgeInsets.only(bottom: 2), + child: Text( + '¥5999', + style: TextStyle( + fontSize: 11, + height: 1, + color: HexColor.fromHex('#b3b3b3'), + fontWeight: FontWeight.normal, + fontFamily: 'Din', + package: 'zhiying_base_widget', + decoration: TextDecoration.lineThrough, + ), + )); + } + + Widget _createPrice() { + return RichText( + maxLines: 1, + overflow: TextOverflow.ellipsis, + text: TextSpan(children: [ + TextSpan( + text: '¥', + style: TextStyle( + fontSize: 10, + color: HexColor.fromHex('#ff4242'), + fontWeight: FontWeight.bold, + fontFamily: 'Din-Bold', + package: 'zhiying_base_widget', + ), + ), + TextSpan( + text: '5299', + style: TextStyle( + fontSize: 20, + color: HexColor.fromHex('#ff4242'), + fontWeight: FontWeight.bold, + fontFamily: 'Din-Bold', + package: 'zhiying_base_widget', + ), + ) + ]), + ); + } + + Widget _createCupone() { + List widgets = List(); + + widgets.add(Container( + margin: EdgeInsets.only(right: 5), + padding: EdgeInsets.only(left: 10, right: 10, top: 3, bottom: 3), + decoration: BoxDecoration( + color: HexColor.fromHex('#ff4242'), + borderRadius: BorderRadius.circular(2.5), + ), + child: Text( + '到手价', + textAlign: TextAlign.center, + maxLines: 1, + style: TextStyle( + height: 1, + fontSize: 11, + color: HexColor.fromHex('#ffffff'), + ), + ), + )); + + return Container( + margin: EdgeInsets.only(top: 6), + child: Row( + children: widgets, + ), + ); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index 0ac7293..740f414 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -19,6 +19,7 @@ dependencies: image_picker: ^0.6.7+3 tab_indicator_styler: 1.0.0 connectivity: ^0.4.9+3 + image_gallery_saver: ^1.5.0 image_cropper: git: url: 'http://192.168.0.138:3000/FnuoOS_Flutter_Components/Image_Cropper.git'