initial
This commit is contained in:
50
lib/packages/html_view/html_view.dart
Normal file
50
lib/packages/html_view/html_view.dart
Normal file
@@ -0,0 +1,50 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:hiddingsel_app/services/environment.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
|
||||
class HtmlView extends StatefulWidget {
|
||||
final String _html;
|
||||
final String html;
|
||||
|
||||
HtmlView(this.html)
|
||||
: _html = Uri.dataFromString(html, mimeType: 'text/html', encoding: utf8)
|
||||
.toString();
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _HtmlViewState();
|
||||
}
|
||||
|
||||
class _HtmlViewState extends State<HtmlView> {
|
||||
|
||||
double? _height;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
WebViewController wbController = WebViewController()
|
||||
..enableZoom(true)
|
||||
..setJavaScriptMode(JavaScriptMode.unrestricted);
|
||||
wbController.setNavigationDelegate(
|
||||
NavigationDelegate(
|
||||
onPageFinished: (String) async {
|
||||
if (_height == null) {
|
||||
var heightString = (await wbController
|
||||
.runJavaScriptReturningResult(
|
||||
'document.documentElement.scrollHeight;'));
|
||||
setState(() {
|
||||
_height = double.parse(heightString.toString());
|
||||
});
|
||||
}
|
||||
}
|
||||
),
|
||||
);
|
||||
wbController.loadHtmlString(widget.html);
|
||||
return SizedBox(
|
||||
height: _height ?? 1,
|
||||
child: WebViewWidget(
|
||||
controller: wbController,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user