Browse Source

1.优化刷新组件

tags/0.0.16+9
“yanghuaxuan” 3 years ago
parent
commit
97b8a0c446
3 changed files with 14 additions and 11 deletions
  1. +9
    -7
      lib/models/base/base_change_notifier.dart
  2. +3
    -0
      lib/models/base/skip_model.dart
  3. +2
    -4
      lib/util/turn_chain/turn_chain_util.dart

+ 9
- 7
lib/models/base/base_change_notifier.dart View File

@@ -6,12 +6,15 @@ import 'package:provider/provider.dart';
class BaseChangeNotifier extends ChangeNotifier { class BaseChangeNotifier extends ChangeNotifier {
StreamController pageController = StreamController.broadcast(); StreamController pageController = StreamController.broadcast();


static Map<String, String> hasKeys = Map();

///刷新通知方法 ///刷新通知方法
void refresh() { void refresh() {
pageController.add("refresh"); pageController.add("refresh");
notifyListeners(); notifyListeners();
} }



void close() { void close() {
pageController.close(); pageController.close();
} }
@@ -29,8 +32,8 @@ enum EventType {
///页面刷新辅助类 ///页面刷新辅助类
class RefreshListener { class RefreshListener {
bool isListen = false; bool isListen = false;
StreamSubscription streamSubscription;
Map<String, String> hasKeys = Map();
StreamSubscription streamSubscription;
///监听方法 ///监听方法
///已废弃 ///已废弃
void _listen(BuildContext context, Function(String) refresh) { void _listen(BuildContext context, Function(String) refresh) {
@@ -54,19 +57,18 @@ class RefreshListener {
} }


///监听构造 ///监听构造
RefreshListener.listen(BuildContext context, Function(String) refresh) {
void listen(BuildContext context, Function(String) refresh) {

BaseChangeNotifier baseChangeNotifier; BaseChangeNotifier baseChangeNotifier;
try { try {
baseChangeNotifier = Provider.of<BaseChangeNotifier>(context); baseChangeNotifier = Provider.of<BaseChangeNotifier>(context);
} catch (e, s) { } catch (e, s) {
print(e); print(e);
print(s); print(s);
throw Exception(
"父页面或父控件必须添加 BaseChangeNotifier 的 Provide值才能使用RefreshListener对象");
} }
if (!isListen && baseChangeNotifier != null) { if (!isListen && baseChangeNotifier != null) {
isListen = true; isListen = true;
baseChangeNotifier.stream.listen((event) {
streamSubscription= baseChangeNotifier.stream.listen((event) {
if (refresh != null) { if (refresh != null) {
refresh(event); refresh(event);
} }
@@ -77,7 +79,7 @@ class RefreshListener {
///关闭监听 ///关闭监听
void close() { void close() {
if (streamSubscription != null) { if (streamSubscription != null) {
streamSubscription.cancel();
streamSubscription?.cancel();
} }
} }
} }

+ 3
- 0
lib/models/base/skip_model.dart View File

@@ -4,6 +4,7 @@ class SkipModel {
String requiredTaobaoAuth; String requiredTaobaoAuth;
String skipIdentifier; String skipIdentifier;
String isJump; String isJump;
String skipName;
Map<String, dynamic> data; Map<String, dynamic> data;


SkipModel({ SkipModel({
@@ -26,6 +27,7 @@ class SkipModel {
requiredTaobaoAuth = json['required_taobao_auth']?.toString(); requiredTaobaoAuth = json['required_taobao_auth']?.toString();
skipIdentifier = json['skip_identifier']; skipIdentifier = json['skip_identifier'];
isJump = json['is_jump']?.toString(); isJump = json['is_jump']?.toString();
skipName=json['skip_name'];
} }


Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@@ -36,6 +38,7 @@ class SkipModel {
data['skip_identifier'] = this.skipIdentifier; data['skip_identifier'] = this.skipIdentifier;
data['is_jump'] = this.isJump; data['is_jump'] = this.isJump;
data['data'] = this.data; data['data'] = this.data;
data['skip_name']=this.skipName;
return data; return data;
} }
} }

+ 2
- 4
lib/util/turn_chain/turn_chain_util.dart View File

@@ -231,10 +231,8 @@ class TurnChainUtil {
RouterUtil.openWebview(webUrl, context); RouterUtil.openWebview(webUrl, context);
rlt = true; rlt = true;
} else { } else {
tradeResult = await FlutterAlibc.openByUrl(
url: openAppUrl,
schemeType: provider == GlobalConfig.PROVIDER_TM ? AlibcSchemeType.AlibcSchemeTmall : AlibcSchemeType.AlibcSchemeTaoBao,
);

tradeResult = await FlutterAlibc.openByUrl(url: openAppUrl,schemeType: provider==GlobalConfig.PROVIDER_TB?AlibcSchemeType.AlibcSchemeTaoBao:AlibcSchemeType.AlibcSchemeTmall,);
rlt = true; rlt = true;
} }
} }


Loading…
Cancel
Save