|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:webview_flutter/webview_flutter.dart';
- import 'dart:async';
-
- class SideBarContent extends StatefulWidget {
- final String html;
- final String title;
-
- SideBarContent({this.title, this.html});
-
- @override
- SideBarContentState createState() {
- return new SideBarContentState();
- }
- }
-
- class SideBarContentState extends State<SideBarContent> {
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text('${widget.title}'),
- ),
- body: SafeArea(
- child: FutureBuilder<String>(
- future: LocalLoader().loadLocal(widget.html),
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- return WebView(
- // HTML code loaded from file
- initialUrl: new Uri.dataFromString(snapshot.data,
- mimeType: 'text/html')
- .toString(),
- javascriptMode: JavascriptMode.unrestricted,
- );
- } else if (snapshot.hasError) {
- return Text("Error trying to load HTML FIle: ${snapshot.error}");
- } else {
- return Container();
- }
- })));
- }
- }
-
- class LocalLoader {
- Future<String> loadLocal(String html) async {
- String response = await rootBundle.loadString(html);
- // return await rootBundle.loadString('assets/yourFile.html');
- return response;
- }
- }
|