Browse Source

Merge branch 'dev' into new_revision_app

new_revision_app
wurong 2 years ago
parent
commit
dfb4450575
  1. 20
      lib/community/community_page.dart
  2. 100
      lib/community/release_dynamic.dart
  3. 170
      lib/utils/upload_async.dart
  4. 6
      lib/vip/vip_page.dart
  5. 4
      lib/vip/vip_view/vip_top.dart
  6. 2
      pubspec.lock
  7. 2
      pubspec.yaml

20
lib/community/community_page.dart

@ -7,6 +7,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/view_widget/my_tab.dart';
import '../generated/l10n.dart';
import '../utils/upload_async.dart';
import 'community_course.dart';
import 'headlines/article_page.dart';
@ -18,7 +19,7 @@ class CommunityPage extends StatefulWidget {
}
class _CommunityPage extends State<CommunityPage>
with SingleTickerProviderStateMixin,AutomaticKeepAliveClientMixin {
with SingleTickerProviderStateMixin,AutomaticKeepAliveClientMixin,UploadObserver {
TabController tabcontroller;
CommunityChildPage guanzhu,tuijian ;
@ -39,13 +40,20 @@ class _CommunityPage extends State<CommunityPage>
@override
void initState() {
super.initState();
UploadInstance.instance.uploadObserverList.add(this);
if (tabcontroller == null)
tabcontroller = TabController(length: lables.length, vsync: this, initialIndex: 1);
}
@override
void dispose() {
super.dispose();
UploadInstance.instance.uploadObserverList.remove(this);
}
void onChildScroll(){
if(scrollCount == 0){
setState(() {
@ -63,8 +71,8 @@ class _CommunityPage extends State<CommunityPage>
});
}
_toRelease() async {
await Navigator.of(context).pushNamed('/router/release_dynamic');
@override
void onUploadFinish(){
if(tabcontroller.index == 0){
CommunityChildPageState page = guanzhuKey.currentState;
page.onRefresh();
@ -74,6 +82,10 @@ class _CommunityPage extends State<CommunityPage>
}
}
_toRelease() async {
Navigator.of(context).pushNamed('/router/release_dynamic');
}
@override
Widget build(BuildContext context) {
return Scaffold(

100
lib/community/release_dynamic.dart

@ -1,21 +1,19 @@
import 'dart:convert';
import 'dart:io';
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_svg/flutter_svg.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/address.dart';
import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/upload_result.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/my_appbar.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:image_pickers/image_pickers.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:thumbnails/thumbnails.dart';
import '../utils/upload_async.dart';
class ReleaseDynamic extends StatefulWidget {
@override
@ -170,99 +168,9 @@ class _ReleaseDynamic extends State<ReleaseDynamic> {
SmartDialog.showToast("请输入您此刻的想法!");
return;
}
EasyLoading.show(status: "上传中");
fileUpload().then((value) async {
String subjectType = "text";
if (dynamicType == 0) {
subjectType = "text";
} else if (dynamicType == 1) {
subjectType = "image";
} else if (dynamicType == 2) {
subjectType = "video";
}
List<String> remoteImageUrls = [];
String remoteVideoUrl = "";
String remoteVideoCoverImg = "";
if (mediaPaths.length > 0) {
if (dynamicType == 1) {
remoteImageUrls = mediaPaths.map((e) => e.remotePath).toList();
} else if (dynamicType == 2) {
remoteVideoUrl = mediaPaths[0].remotePath;
remoteVideoCoverImg = mediaPaths[0].thumbPath;
}
}
BaseData<bool> baseData = await apiService.trend({
"images": remoteImageUrls,
"subject": dynamicText,
"subjectType": subjectType,
"video": remoteVideoUrl,
"coverImg": remoteVideoCoverImg,
"latitude": "",
"location": addressController.text == "" ? "" : addressController.text,
"longitude": "",
}).catchError((onError) {
EasyLoading.dismiss();
});
if (baseData != null && baseData.isSuccess) {
SmartDialog.showToast("发布成功!");
Future.delayed(Duration(seconds: 1), () {
Navigator.of(context).pop(true);
});
} else {
SmartDialog.showToast(baseData.msg, alignment: Alignment.center);
}
EasyLoading.dismiss();
});
}
///
Future<void> fileUpload() async {
if (mediaPaths != null && mediaPaths.length > 0) {
await Future.forEach(mediaPaths, (element) async {
if ((element.remotePath == null || element.remotePath == "") &&
(element != null &&
element.path != null &&
element.path != "" &&
await File(element.path).exists())) {
File file = File(element.path);
if (dynamicType == 2) {
String thumbnail;
if (element.thumbPath != null &&
element.thumbPath != "" &&
await File(element.thumbPath).exists()) {
thumbnail = element.thumbPath;
} else {
thumbnail = await Thumbnails.getThumbnail(
videoFile: file.path,
imageType: ThumbFormat.JPEG,
quality: 10,
);
}
if (thumbnail != null &&
thumbnail != "" &&
await File(thumbnail).exists()) {
BaseData<UploadResult> baseData = await apiService.upload(
File(thumbnail), 123123123, dynamicType == 2);
if (baseData != null && baseData.isSuccess) {
UploadResult uploadResult = baseData.data;
mediaPaths[mediaPaths.indexOf(element)].thumbPath =
uploadResult.url;
}
}
}
BaseData<UploadResult> baseData =
await apiService.upload(file, 123123123, dynamicType == 2);
if (baseData != null && baseData.isSuccess) {
UploadResult uploadResult = baseData.data;
mediaPaths[mediaPaths.indexOf(element)].remotePath =
uploadResult.url;
}
}
});
}
UploadAsync.upload(dynamicType, mediaPaths, addressController.text, dynamicText);
Navigator.of(context).pop();
}
Widget imageItem(Medias media) {

170
lib/utils/upload_async.dart

@ -0,0 +1,170 @@
import 'dart:io';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:thumbnails/thumbnails.dart';
import '../community/release_dynamic.dart';
import '../retrofit/data/base_data.dart';
import '../retrofit/data/upload_result.dart';
import '../retrofit/retrofit_api.dart';
class UploadAsync {
static void upload(int dynamicType, List<Medias> mediaPaths,
String addressText, String dynamicText) async {
SmartDialog.show(
widget: Container(
alignment: Alignment.centerRight,
margin: EdgeInsets.only(
right: 10.w,
),
child: CircularProgressIndicator(
strokeWidth: 4.0,
backgroundColor: Colors.green,
// value: 0.4,
valueColor: new AlwaysStoppedAnimation<Color>(Colors.grey),
),
),
maskWidgetTemp: SizedBox(),
);
var sp = await SharedPreferences.getInstance();
ApiService apiService = ApiService(
Dio(),
token: sp.getString("token"),
showLoading: false,
);
fileUpload(apiService, mediaPaths, dynamicType).then((value) async {
String subjectType = "text";
if (dynamicType == 0) {
subjectType = "text";
} else if (dynamicType == 1) {
subjectType = "image";
} else if (dynamicType == 2) {
subjectType = "video";
}
List<String> remoteImageUrls = [];
String remoteVideoUrl = "";
String remoteVideoCoverImg = "";
if (mediaPaths.length > 0) {
if (dynamicType == 1) {
remoteImageUrls = mediaPaths.map((e) => e.remotePath).toList();
} else if (dynamicType == 2) {
remoteVideoUrl = mediaPaths[0].remotePath;
remoteVideoCoverImg = mediaPaths[0].thumbPath;
}
}
BaseData<bool> baseData = await apiService.trend({
"images": remoteImageUrls,
"subject": dynamicText,
"subjectType": subjectType,
"video": remoteVideoUrl,
"coverImg": remoteVideoCoverImg,
"latitude": "",
"location": addressText,
"longitude": "",
}).catchError((onError) {
SmartDialog.dismiss();
});
if (baseData != null && baseData.isSuccess) {
SmartDialog.showToast("发布成功!");
UploadInstance.instance.notifyAllObservers();
} else {
SmartDialog.showToast(baseData.msg, alignment: Alignment.center);
}
SmartDialog.dismiss();
});
}
///
static Future<void> fileUpload(
ApiService apiService, List<Medias> mediaPaths, int dynamicType) async {
if (mediaPaths != null && mediaPaths.length > 0) {
await Future.forEach(mediaPaths, (element) async {
if ((element.remotePath == null || element.remotePath == "") &&
(element != null &&
element.path != null &&
element.path != "" &&
await File(element.path).exists())) {
File file = File(element.path);
if (dynamicType == 2) {
String thumbnail;
if (element.thumbPath != null &&
element.thumbPath != "" &&
await File(element.thumbPath).exists()) {
thumbnail = element.thumbPath;
} else {
thumbnail = await Thumbnails.getThumbnail(
videoFile: file.path,
imageType: ThumbFormat.JPEG,
quality: 10,
);
}
if (thumbnail != null &&
thumbnail != "" &&
await File(thumbnail).exists()) {
BaseData<UploadResult> baseData = await apiService.upload(
File(thumbnail), 123123123, dynamicType == 2);
if (baseData != null && baseData.isSuccess) {
UploadResult uploadResult = baseData.data;
mediaPaths[mediaPaths.indexOf(element)].thumbPath =
uploadResult.url;
}
}
}
BaseData<UploadResult> baseData =
await apiService.upload(file, 123123123, dynamicType == 2);
if (baseData != null && baseData.isSuccess) {
UploadResult uploadResult = baseData.data;
mediaPaths[mediaPaths.indexOf(element)].remotePath =
uploadResult.url;
}
}
});
}
}
}
abstract class UploadObserver {
void onUploadFinish();
}
class UploadInstance {
factory UploadInstance() => _getInstance();
static UploadInstance get instance => _getInstance();
static UploadInstance _instance;
List<UploadObserver> _uploadObserverList;
List<UploadObserver> get uploadObserverList => _uploadObserverList;
set uploadObserverList(List<UploadObserver> value) {
_uploadObserverList = value;
}
UploadInstance._internal() {
//
_uploadObserverList = [];
}
static UploadInstance _getInstance() {
if (_instance == null) {
_instance = UploadInstance._internal();
}
return _instance;
}
void notifyAllObservers(){
_uploadObserverList.forEach((element) {
element.onUploadFinish();
});
}
}

6
lib/vip/vip_page.dart

@ -59,12 +59,14 @@ class _VipPageState extends State<VipPage> with AutomaticKeepAliveClientMixin {
await apiService.vipCardIndex().catchError((onError) {
SmartDialog.showToast(AppUtils.dioErrorTypeToString(onError.type),
alignment: Alignment.center);
_refreshController.refreshFailed();});
_refreshController.loadFailed();
_refreshController.refreshFailed();
});
if (baseData != null && baseData.isSuccess) {
vipHome = baseData.data;
_refreshController.refreshCompleted();
_refreshController.loadComplete();
}else{
_refreshController.refreshFailed();
SmartDialog.showToast(baseData.msg ?? "", alignment: Alignment.center);
}
}finally{

4
lib/vip/vip_view/vip_top.dart

@ -51,7 +51,7 @@ class _VipTop extends State<VipTop> {
});
}
recharge() async {
rechargeVIP() async {
if (apiService == null) {
SharedPreferences value = await SharedPreferences.getInstance();
apiService = ApiService(Dio(),
@ -895,7 +895,7 @@ class _VipTop extends State<VipTop> {
GestureDetector(
onTap: () {
Navigator.of(context).pop();
recharge();
rechargeVIP();
},
child: Container(
height: double.infinity,

2
pubspec.lock

@ -269,7 +269,7 @@ packages:
name: flutter_smart_dialog
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.6"
version: "3.5.0"
flutter_spinkit:
dependency: "direct main"
description:

2
pubspec.yaml

@ -57,7 +57,7 @@ dependencies:
event_bus: ^2.0.0
intl: ^0.17.0
shared_preferences: ^2.0.6
flutter_smart_dialog: ^2.1.6
flutter_smart_dialog: ^3.0.6
barcode_widget: ^2.0.1
qr_flutter: ^4.0.0

Loading…
Cancel
Save