Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加FairWidget支持httpurl资源加载 #340

Merged
merged 2 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading