我想从本地 html 文件中的链接开始新页面。
我想从 webview(Page_one) 转到 Page_two.dart 页面。我加载的 webview 没问题。
<p style="margin-left: 30px;">Read <a style= "text-decoration: none;"
href="Page_two.dart">Prohibited ads</a></p></n>
这是我的 Page_one.dart 文件
class LoadHTMLFileToWEbView extends StatefulWidget {
@override
_LoadHTMLFileToWEbViewState createState() =>
_LoadHTMLFileToWEbViewState();
}
class _LoadHTMLFileToWEbViewState extends State<LoadHTMLFileToWEbView> {
@override
Widget build(BuildContext context) {
return FutureBuilder<String>(
future: _loadLocalHTML(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return WebviewScaffold(
appBar: AppBar(title: Text("Load HTM file in WebView")),
withJavascript: true,
appCacheEnabled: true,
url: new Uri.dataFromString(snapshot.data, mimeType: 'text/html' , encoding: utf8)
.toString(),
);
} else if (snapshot.hasError) {
return Scaffold(
body: Center(
child: Text("${snapshot.error}"),
),
);
}
return Scaffold(
body: Center(child: CircularProgressIndicator()),
);
},
);
}
}
Future<String> _loadLocalHTML() async {
return await rootBundle.loadString('assets/test.html');
}