Skip to content

Commit 2164b75

Browse files
authored
chore: update Java version to 11, Android plugin to 8.2.1, and webview_flutter to ^4.0.10 (#32)(#33)
Initially, the application was compiled for Android. To do this, the following were required: JavaVersion.VERSION_11 id "com.android.application" version "8.2.1" apply false The dependency webview_flutter: ^4.0.10 It was also necessary to update the about_file_screen.dart file, which uses this library, and to take the library update into account to ensure compatibility with newer versions.
1 parent 46dc751 commit 2164b75

File tree

8 files changed

+293
-153
lines changed

8 files changed

+293
-153
lines changed

app/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
*.swp
66
.DS_Store
77
.atom/
8+
.build/
89
.buildlog/
910
.history
1011
.svn/
12+
.swiftpm/
1113
migrate_working_dir/
1214

1315
# IntelliJ related

app/android/app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ android {
1111
ndkVersion = flutter.ndkVersion
1212

1313
compileOptions {
14-
sourceCompatibility = JavaVersion.VERSION_1_8
15-
targetCompatibility = JavaVersion.VERSION_1_8
14+
sourceCompatibility = JavaVersion.VERSION_11
15+
targetCompatibility = JavaVersion.VERSION_11
1616
}
1717

1818
kotlinOptions {
19-
jvmTarget = JavaVersion.VERSION_1_8
19+
jvmTarget = JavaVersion.VERSION_11
2020
}
2121

2222
defaultConfig {

app/android/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pluginManagement {
1818

1919
plugins {
2020
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
21-
id "com.android.application" version "8.1.0" apply false
21+
id "com.android.application" version "8.2.1" apply false
2222
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
2323
}
2424

app/ios/Podfile.lock

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,25 @@ PODS:
44
- Flutter
55
- webview_flutter_wkwebview (0.0.1):
66
- Flutter
7+
- FlutterMacOS
78

89
DEPENDENCIES:
910
- Flutter (from `Flutter`)
1011
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)
11-
- webview_flutter_wkwebview (from `.symlinks/plugins/webview_flutter_wkwebview/ios`)
12+
- webview_flutter_wkwebview (from `.symlinks/plugins/webview_flutter_wkwebview/darwin`)
1213

1314
EXTERNAL SOURCES:
1415
Flutter:
1516
:path: Flutter
1617
url_launcher_ios:
1718
:path: ".symlinks/plugins/url_launcher_ios/ios"
1819
webview_flutter_wkwebview:
19-
:path: ".symlinks/plugins/webview_flutter_wkwebview/ios"
20+
:path: ".symlinks/plugins/webview_flutter_wkwebview/darwin"
2021

2122
SPEC CHECKSUMS:
2223
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
2324
url_launcher_ios: 694010445543906933d732453a59da0a173ae33d
24-
webview_flutter_wkwebview: 6e6160e04b1e85872253adc5322afe416d9cdddc
25+
webview_flutter_wkwebview: 44d4dee7d7056d5ad185d25b38404436d56c547c
2526

2627
PODFILE CHECKSUM: 819463e6a0290f5a72f145ba7cde16e8b6ef0796
2728

app/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 49 additions & 49 deletions
Large diffs are not rendered by default.

app/lib/ui/about/detail/about_file_screen.dart

Lines changed: 83 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ import 'package:flutter/material.dart';
1818
import 'package:flutter/services.dart';
1919
import 'package:markdown/markdown.dart' as md;
2020
import 'package:ouds_flutter_demo/main_app_bar.dart';
21-
import 'package:path/path.dart' as path;
2221
import 'package:webview_flutter/webview_flutter.dart';
2322

24-
class AboutFileScreen extends StatelessWidget {
23+
class AboutFileScreen extends StatefulWidget {
2524
final String title;
2625
final String fileMenuItem;
2726
final bool darkModeEnabled;
@@ -33,56 +32,57 @@ class AboutFileScreen extends StatelessWidget {
3332
required this.darkModeEnabled});
3433

3534
@override
36-
Widget build(BuildContext context) {
37-
final colors = Theme.of(context).colorScheme;
38-
const horizontalPadding = 13.0;
39-
const verticalPadding = 13.0;
35+
AboutFileScreenState createState() => AboutFileScreenState();
36+
}
4037

41-
return Scaffold(
42-
appBar: MainAppBar(title: title, showBackButton: true),
43-
body: SafeArea(
44-
child: FutureBuilder(
45-
future: _loadFileData(),
46-
builder: (context, snapshot) {
47-
if (snapshot.connectionState == ConnectionState.done) {
48-
String markdownContent = snapshot.data as String;
49-
50-
/// Convert Markdown to HTML using the markdown package
51-
String htmlContent = markdownToHtml(markdownContent);
52-
53-
return WebView(
54-
initialUrl: 'about:blank',
55-
onWebViewCreated: (WebViewController webViewController) {
56-
webViewController.loadUrl(Uri.dataFromString(
57-
_wrapHtmlWithCss(
58-
htmlContent,
59-
darkModeEnabled,
60-
colors,
61-
horizontalPadding,
62-
verticalPadding,
63-
),
64-
mimeType: 'text/html',
65-
encoding: Encoding.getByName('utf-8'),
66-
).toString());
67-
},
68-
backgroundColor: Colors.transparent,
69-
);
70-
} else {
71-
return const Center(child: CircularProgressIndicator());
72-
}
73-
},
74-
),
75-
),
76-
);
38+
class AboutFileScreenState extends State<AboutFileScreen> {
39+
late WebViewController _webViewController;
40+
41+
/// Padding
42+
final double horizontalPadding = 13.0;
43+
final double verticalPadding = 13.0;
44+
45+
@override
46+
void initState() {
47+
super.initState();
48+
49+
/// Initialize WebViewController
50+
_webViewController = WebViewController()
51+
..setJavaScriptMode(JavaScriptMode.unrestricted)
52+
..setBackgroundColor(Colors.transparent);
53+
54+
/// Initialize WebView and load content
55+
_initializeWebView();
7756
}
7857

79-
bool isHTMLFile(String filePath) {
80-
String extension = path.extension(filePath);
81-
return extension.toLowerCase() == '.html';
58+
Future<void> _initializeWebView() async {
59+
String markdownContent = await _loadFileData();
60+
String htmlContent = markdownToHtml(markdownContent);
61+
62+
/// Check if the widget is still mounted before using the context
63+
if (!mounted) return;
64+
65+
/// Wrap the HTML content with necessary CSS
66+
String wrappedHtml = _wrapHtmlWithCss(
67+
htmlContent,
68+
widget.darkModeEnabled,
69+
Theme.of(context).colorScheme,
70+
horizontalPadding,
71+
verticalPadding,
72+
);
73+
74+
/// Load HTML content into the WebViewController
75+
_webViewController.loadRequest(
76+
Uri.dataFromString(
77+
wrappedHtml,
78+
mimeType: 'text/html',
79+
encoding: Encoding.getByName('utf-8'),
80+
),
81+
);
8282
}
8383

8484
Future<String> _loadFileData() async {
85-
return await rootBundle.loadString(fileMenuItem);
85+
return await rootBundle.loadString(widget.fileMenuItem);
8686
}
8787

8888
String markdownToHtml(String markdownContent) {
@@ -150,7 +150,7 @@ a:link {
150150

151151
String themeStyle = darkModeEnabled ? lightStyle : darkStyle;
152152

153-
String cssApple = '''<style type="text/css">
153+
String cssApple = '''<style ="text/css">
154154
html {
155155
font: -apple-system-body;
156156
}
@@ -202,7 +202,7 @@ a:link {
202202
color: #527EDB;
203203
}
204204
</style>''';
205-
String cssAndroid = '''<style type="text/css">
205+
String cssAndroid = '''<style ="text/css">
206206
body {
207207
padding: 0;
208208
-webkit-text-size-adjust: none;
@@ -293,40 +293,52 @@ a:link {
293293

294294
return convertToHtml(fileContent, cssApple, cssAndroidThemeStyle);
295295
}
296-
}
297296

298-
String convertToHtml(
299-
String partialHTMLText, String cssApple, String cssAndroid) {
300-
String head = """
297+
String convertToHtml(
298+
String partialHTMLText, String cssApple, String cssAndroid) {
299+
String head = """
301300
<!doctype html>
302301
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no'>
303302
""";
304303

305-
if (partialHTMLText.contains("<html")) {
306-
return partialHTMLText;
307-
}
304+
if (partialHTMLText.contains("<html")) {
305+
return partialHTMLText;
306+
}
308307

309-
var result = "<html>";
310-
result += head;
308+
var result = "<html>";
309+
result += head;
311310

312-
if (!kIsWeb) {
313-
if (Platform.isIOS) {
314-
result += cssApple;
315-
} else {
316-
if (Platform.isAndroid) {
317-
result += cssAndroid;
311+
if (!kIsWeb) {
312+
if (Platform.isIOS) {
313+
result += cssApple;
314+
} else {
315+
if (Platform.isAndroid) {
316+
result += cssAndroid;
317+
}
318318
}
319319
}
320-
}
321320

322-
result += "</head>";
321+
result += "</head>";
322+
323+
if (partialHTMLText.contains("<body")) {
324+
result += partialHTMLText;
325+
} else {
326+
result += "<body><p dir=\"auto\">$partialHTMLText</p></body>";
327+
}
323328

324-
if (partialHTMLText.contains("<body")) {
325-
result += partialHTMLText;
326-
} else {
327-
result += "<body><p dir=\"auto\">$partialHTMLText</p></body>";
329+
result += "</html>";
330+
return result;
328331
}
329332

330-
result += "</html>";
331-
return result;
333+
@override
334+
Widget build(BuildContext context) {
335+
return Scaffold(
336+
appBar: MainAppBar(title: widget.title, showBackButton: true),
337+
body: SafeArea(
338+
child: WebViewWidget(
339+
controller: _webViewController,
340+
),
341+
),
342+
);
343+
}
332344
}

0 commit comments

Comments
 (0)