Просмотр исходного кода

1.webview添加进度条

2.自购省添加免单请求参数
tags/0.0.4+7
“yanghuaxuan” 3 лет назад
Родитель
Сommit
33e6d216a3
4 измененных файлов: 140 добавлений и 70 удалений
  1. +28
    -27
      example/android/app/build.gradle
  2. +13
    -6
      lib/pages/goods_details_page/goods_details_page.dart
  3. +94
    -32
      lib/pages/webview/base_webview.dart
  4. +5
    -5
      lib/widgets/goods_details/footer/goods_details_footer_widget.dart

+ 28
- 27
example/android/app/build.gradle Просмотреть файл

@@ -108,33 +108,33 @@ android {


// 应用信息配置
// productFlavors {
// // 智夜生活
// zhiying {
// applicationId "cn.zhios.zhiying"
// versionCode 31
// dimension "app"
// versionName '1.2.31'
// // 签名信息
// signingConfig signingConfigs.zhiying
// }
// }
//
// // 打包脚本
// android.applicationVariants.all { variant ->
// if (variant.buildType.name != "debug") {
// variant.getPackageApplicationProvider().get().outputDirectory = new File(project.rootDir.absolutePath + "/app/build/outputs/apk")
// }
//
// variant.outputs.all { output ->
// def outputFile = output.outputFile
// if (outputFile != null && outputFile.name.endsWith('.apk')) {
// //这里修改apk文件名
// def fileName = "${variant.productFlavors[0].name}_${releaseTime()}01_&V${variant.productFlavors[0].versionCode}.apk"
// outputFileName = fileName
// }
// }
// }
productFlavors {
// 智夜生活
zhiying {
applicationId "cn.zhios.zhiying"
versionCode 32
dimension "app"
versionName '1.2.32'
// 签名信息
signingConfig signingConfigs.zhiying
}
}
// 打包脚本
android.applicationVariants.all { variant ->
if (variant.buildType.name != "debug") {
variant.getPackageApplicationProvider().get().outputDirectory = new File(project.rootDir.absolutePath + "/app/build/outputs/apk")
}
variant.outputs.all { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
//这里修改apk文件名
def fileName = "${variant.productFlavors[0].name}_${releaseTime()}01_&V${variant.productFlavors[0].versionCode}.apk"
outputFileName = fileName
}
}
}

configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
@@ -215,6 +215,7 @@ MobSDK {
Wechat {
appId "wx598aaef252cd78e4"
appSecret "d2fc2edf9ece746765b3bfc0bf1b230e"
shareByAppClient true
withShareTicket true
bypassApproval false
enable true


+ 13
- 6
lib/pages/goods_details_page/goods_details_page.dart Просмотреть файл

@@ -19,8 +19,9 @@ import 'notifier/goods_details_appbar_color_notifier.dart';

class GoodsDetailsPage extends StatefulWidget {
final Map<String, dynamic> data;
final bool isFree;

GoodsDetailsPage(this.data, {Key key}) : super(key: key);
GoodsDetailsPage(this.data, {this.isFree = false, Key key}) : super(key: key);

@override
_GoodsDetailsPageState createState() => _GoodsDetailsPageState();
@@ -43,9 +44,11 @@ class _GoodsDetailsPageState extends State<GoodsDetailsPage> {
ChangeNotifierProvider.value(value: GoodsDetailsAppBarColorNotifier()),
],
child: BlocProvider<GoodsDetailsPageBloc>(
create: (_) => GoodsDetailsPageBloc(repository: GoodsDetailsPageRepository())
..add(GoodsDetailsPageInitEvent(model: widget?.data)),
child: GoodsDetailsContainer(widget?.data),
create: (_) => GoodsDetailsPageBloc(repository: GoodsDetailsPageRepository())..add(GoodsDetailsPageInitEvent(model: widget?.data)),
child: GoodsDetailsContainer(
widget?.data,
isFree: widget?.isFree,
),
),
);
}
@@ -53,8 +56,9 @@ class _GoodsDetailsPageState extends State<GoodsDetailsPage> {

class GoodsDetailsContainer extends StatefulWidget {
final Map<String, dynamic> data;
final bool isFree;

const GoodsDetailsContainer(this.data);
const GoodsDetailsContainer(this.data, {this.isFree = false});

@override
_GoodsDetailsContainerState createState() => _GoodsDetailsContainerState();
@@ -160,7 +164,10 @@ class _GoodsDetailsContainerState extends State<GoodsDetailsContainer> {
)),

/// 底部
bottomNavigationBar: GoodsDetailsFooterWidget(!EmptyUtil.isEmpty(datas) ? datas[datas.length - 1] : null),
bottomNavigationBar: GoodsDetailsFooterWidget(
!EmptyUtil.isEmpty(datas) ? datas[datas.length - 1] : null,
isFree: widget.isFree,
),
);
}



+ 94
- 32
lib/pages/webview/base_webview.dart Просмотреть файл

@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:io';

import 'package:flutter/cupertino.dart';
@@ -24,6 +25,8 @@ class _BaseWebviewState extends State<BaseWebview> {
String _title;
WebViewController _webViewController;
bool _isiOSReview = false;
double progress = 0.0;
Timer timer;

@override
void initState() {
@@ -31,6 +34,37 @@ class _BaseWebviewState extends State<BaseWebview> {
_settingIosReview();
super.initState();
}

@override
void dispose() {
// TODO: implement dispose
timer?.cancel();
super.dispose();
}

loadData() {
print("加载数据");
progress = 0.0;
if(timer?.isActive??false){
timer?.cancel();
}
timer = Timer.periodic(Duration(milliseconds: 10), (timer) {
if (progress > 0.8) {
progress = progress + 0.01;
} else if (progress > 0.7) {
progress = progress + 0.002;
} else if (progress > 0.5) {
progress += 0.005;
} else {
progress = progress + 0.01;
}
if (progress > 1.1) {
timer.cancel();
}
setState(() {});
});
}

void _settingIosReview() async {
String is_ios_review = await SharedPreferencesUtil.getStringValue(GlobalConfig.IS_IOS_REVIEW, defaultVal: '0');
setState(() {
@@ -40,42 +74,53 @@ class _BaseWebviewState extends State<BaseWebview> {
}
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: _createNav(),
backgroundColor: Colors.white,
body: WebView(
initialUrl: _url,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_webViewController = webViewController;
},
navigationDelegate: (NavigationRequest request) async{
// 解决Android的拼多多webview 转发的问题
if(Platform.isAndroid){
String url = request?.url?.toString();
if(!EmptyUtil.isEmpty(url) && !url.startsWith('https://') && !url.startsWith('http://')){
Logger.log('navigation url = $url');
// if(await canLaunch(url)){
// await launch(url);
// }
return NavigationDecision.prevent;
}
}
return NavigationDecision.navigate;
},
onPageStarted: (String url) {
print('Page started loading: $url');
},
onPageFinished: (String url) {
print('Page finished loading: $url');
_webViewController.getTitle().then((title) {
_title = title;
setState(() {});
});
},
gestureNavigationEnabled: true,
body: Stack(
children: <Widget>[
WebView(
initialUrl: _url,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_webViewController = webViewController;
loadData();
},
navigationDelegate: (NavigationRequest request) async {
// 解决Android的拼多多webview 转发的问题
if (Platform.isAndroid) {
String url = request?.url?.toString();
if (!EmptyUtil.isEmpty(url) && !url.startsWith('https://') && !url.startsWith('http://')) {
Logger.log('navigation url = $url');
// if(await canLaunch(url)){
// await launch(url);
// }
return NavigationDecision.prevent;
}
}
return NavigationDecision.navigate;
},
onPageStarted: (String url) {
print('Page started loading: $url');
},
onPageFinished: (String url) {
if(progress<0.8){
progress = 0.8;
}
setState(() {});
print('Page finished loading: $url');
_webViewController.getTitle().then((title) {
_title = title;
setState(() {});
});
},
gestureNavigationEnabled: true,
),
progress <= 1.0 ? _createProgress() : Container(),
],
),
);
}
@@ -115,11 +160,28 @@ class _BaseWebviewState extends State<BaseWebview> {
),
),
trailing: GestureDetector(
child: _isiOSReview ? Container() : Icon(Icons.refresh, size: 20,),
child: _isiOSReview
? Container()
: Icon(
Icons.refresh,
size: 20,
),
onTap: () {
_webViewController.reload();
loadData();
},
),
);
}

_createProgress() {
return Container(
constraints: BoxConstraints(maxHeight: 2),
child: LinearProgressIndicator(
backgroundColor: Colors.white,
valueColor: AlwaysStoppedAnimation<Color>(Colors.red),
value: progress,
),
);
}
}

+ 5
- 5
lib/widgets/goods_details/footer/goods_details_footer_widget.dart Просмотреть файл

@@ -20,8 +20,8 @@ import 'package:zhiying_comm/util/turn_chain/turn_chain_util.dart';
///
class GoodsDetailsFooterWidget extends StatelessWidget {
final Map<String, dynamic> model;
const GoodsDetailsFooterWidget(this.model);
final bool isFree;
const GoodsDetailsFooterWidget(this.model,{this.isFree});

@override
Widget build(BuildContext context) {
@@ -42,8 +42,8 @@ class GoodsDetailsFooterWidget extends StatelessWidget {

class _GoodsDetailsFooterContainer extends StatefulWidget {
final Map<String, dynamic> model;
const _GoodsDetailsFooterContainer(this.model, {Key key}) : super(key: key);
final bool isFree;
const _GoodsDetailsFooterContainer(this.model, {this.isFree,Key key}) : super(key: key);

@override
_GoodsDetailsFooterContainerState createState() => _GoodsDetailsFooterContainerState();
@@ -104,7 +104,7 @@ class _GoodsDetailsFooterContainerState extends State<_GoodsDetailsFooterContain

/// 自购省
void _saveMoneyOnClick(GoodsDetailsFooterModel model) async {
await TurnChainUtil.openReceiveCoupon(context, _user, model?.good_id, model?.provider, model?.convertArgs?.toJson());
await TurnChainUtil.openReceiveCoupon(context, _user, model?.good_id, model?.provider, model?.convertArgs?.toJson(),isFree: widget?.isFree);
}

@override


Загрузка…
Отмена
Сохранить