初始化
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:hgdj/assets_tool/images.dart';
|
||||
import 'package:hgdj/tools_base/unique_tag_mixin.dart';
|
||||
|
||||
import 'h5_logic.dart';
|
||||
import 'h5_webview_settings.dart';
|
||||
|
||||
class H5Page extends StatefulWidget {
|
||||
final String? url;
|
||||
final String? title;
|
||||
final bool isNeedScaffold;
|
||||
final bool showTitle;
|
||||
final bool showClose;
|
||||
|
||||
const H5Page({
|
||||
super.key,
|
||||
this.url,
|
||||
this.title,
|
||||
this.isNeedScaffold = true,
|
||||
this.showTitle = true,
|
||||
this.showClose = false,
|
||||
});
|
||||
|
||||
@override
|
||||
State<H5Page> createState() => _H5PageState();
|
||||
}
|
||||
|
||||
class _H5PageState extends State<H5Page> with UniqueTagMixin {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GetBuilder<H5Logic>(
|
||||
tag: uniqueTag, // H5 可跳 H5、多实例并存,用 uniqueTag 隔离各自 logic
|
||||
init: H5Logic(url: widget.url),
|
||||
builder: (logic) {
|
||||
return Scaffold(
|
||||
appBar:
|
||||
widget.showTitle ? AppBar(title: Text(widget.title ?? "")) : null,
|
||||
body: SafeArea(
|
||||
child: Stack(
|
||||
children: [
|
||||
_webView(logic),
|
||||
if (widget.showClose) _closeButton(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _webView(H5Logic logic) {
|
||||
return InAppWebView(
|
||||
initialUrlRequest: logic.initialUrlRequest,
|
||||
initialSettings: h5WebViewSettings,
|
||||
initialUserScripts: UnmodifiableListView<UserScript>([]),
|
||||
onWebViewCreated: logic.onWebViewCreated,
|
||||
onLoadStart: (_, url) => debugPrint("onPageFinished$url"),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _closeButton() {
|
||||
return Positioned(
|
||||
top: 20,
|
||||
right: 16,
|
||||
child: InkWell(
|
||||
enableFeedback: false,
|
||||
onTap: () => Get.back(),
|
||||
child: Image.asset('search_close.png'.commonImgPath, width: 30),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user