Skip to content

Commit

Permalink
Merge pull request #340 from hc2088/main
Browse files Browse the repository at this point in the history
添加FairWidget支持httpurl资源加载
  • Loading branch information
wanbing authored Sep 8, 2023
2 parents 248f73b + 4112fd9 commit c8c326c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
3 changes: 3 additions & 0 deletions fair/lib/src/internal/flexbuffer/fair_js_decoder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class FairJSFairJSDecoderHelper {
return beforePath;
}
if (beforePath.startsWith('http')) {
if (beforePath.endsWith('.json') || beforePath.endsWith('.bin')) {
beforePath = beforePath.replaceFirst(RegExp(r"\.(json|bin)$"), ".js");
}
return beforePath;
} else {
//加载其它路径判断待定
Expand Down
2 changes: 1 addition & 1 deletion fair/lib/src/runtime/fair_message_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class FairHandler {
}

void register(FairMessageCallback<String> state) {
log('register state: ${state.getMessageKey}');
log('register state: ${state.getMessageKey()}');
pageHistories[state.getMessageKey()] = state;
}

Expand Down
24 changes: 14 additions & 10 deletions fair/lib/src/widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,13 @@ class FairState extends State<FairWidget> with Loader, AutomaticKeepAliveClientM
if (mounted) {
var name = state2key;
var path = widget.path ?? _fairApp!.pathOfBundle(widget.name ?? '');
if (path?.endsWith('.js') == true) {
path = path?.replaceFirst(RegExp(r"\.(js)$"), ".bin");
}
bundleType =
widget.path != null && widget.path?.startsWith('http') == true
? 'Http'
: 'Asset';
widget.path != null && widget.path?.startsWith('http') == true
? 'Http'
: 'Asset';

parse(context, page: name, url: path, data: widget.data ?? {})
.then((value) {
Expand All @@ -208,20 +211,21 @@ class FairState extends State<FairWidget> with Loader, AutomaticKeepAliveClientM
stackTrace: jsSource,
highlightLines: [loadJsErrorLineNumber ?? -1],
solution:
'Unsupported JavaScript syntax, please check and correct your Dart method coding!',
'Unsupported JavaScript syntax, please check and correct your Dart method coding!',
),
);
}
var builder = widget.holder ?? _fairApp?.placeholderBuilder;
var result = _child ?? builder?.call(context);
if (!kReleaseMode && _fairApp!.debugShowFairBanner) {
result = _CheckedModeBanner(bundleType??'', child: result??Container());
result =
_CheckedModeBanner(bundleType ?? '', child: result ?? Container());
}
return result??Container();
return result ?? Container();
}

@override
bool get wantKeepAlive => widget.wantKeepAlive??false;
bool get wantKeepAlive => widget.wantKeepAlive ?? false;

/// Implementations of this method should end with a call to the inherited
/// method, as in `super.dispose()`.
Expand All @@ -237,9 +241,9 @@ class FairState extends State<FairWidget> with Loader, AutomaticKeepAliveClientM

@override
void call(String t) {
var params={};
var params = {};
try {
params= jsonDecode(t);
params = jsonDecode(t);
} catch (e) {
print(e);
}
Expand All @@ -253,7 +257,7 @@ class FairState extends State<FairWidget> with Loader, AutomaticKeepAliveClientM
/// Delegate for business logic. The delegate share similar life-circle with [State].
class FairDelegate extends RuntimeFairDelegate {
FairState? _state;
late String _key;
late String _key;

void _bindState(FairState? state) {
assert(state != null, 'FairState should not be null');
Expand Down

0 comments on commit c8c326c

Please sign in to comment.