-
Notifications
You must be signed in to change notification settings - Fork 12
/
webview_controller_extension.dart
40 lines (34 loc) · 1.35 KB
/
webview_controller_extension.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Flutter imports:
import 'package:flutter/services.dart';
// Package imports:
import 'package:webview_flutter/webview_flutter.dart';
extension type WebViewControllerExtension(WebViewController controller)
implements WebViewController {
/// used to load the emergency procedures html files inside the webView
Future loadHtmlFromAssets(String filename, Brightness brightness) async {
final String fileText = await rootBundle.loadString(filename);
final String data = darkMode(scaleText(fileText), brightness);
await loadHtmlString(data);
}
/// used to add dark theme to emergency procedures html files
String darkMode(String fileText, Brightness brightness) {
String colorFileText = fileText;
if (brightness == Brightness.dark) {
colorFileText = colorFileText.replaceAll('<html>',
'<html><style> body { background-color: black; color: white;} </style>');
}
return colorFileText;
}
String scaleText(String fileText) {
return fileText.replaceAll(
'<html>',
// ignore: missing_whitespace_between_adjacent_strings
"<html><meta name="
"viewport"
// ignore: missing_whitespace_between_adjacent_strings
" content="
// ignore: missing_whitespace_between_adjacent_strings
'width=device-width, initial-scale=1.0'
">");
}
}