Skip to content

Commit d2ec30a

Browse files
authored
Merge pull request #43 from headlines-toolkit/feature_web_build_loading_screen
Feature web build loading screen
2 parents 1c01728 + 7009794 commit d2ec30a

File tree

4 files changed

+74
-14
lines changed

4 files changed

+74
-14
lines changed

lib/main.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import 'dart:js_interop';
2+
3+
import 'package:device_preview/device_preview.dart';
14
import 'package:flutter/foundation.dart';
25
import 'package:flutter/material.dart';
3-
import 'package:device_preview/device_preview.dart';
46
import 'package:ht_main/app/config/config.dart';
57
import 'package:ht_main/bootstrap.dart';
68

@@ -9,6 +11,9 @@ import 'package:ht_main/bootstrap.dart';
911
// production/development/demo
1012
const currentEnvironment = AppEnvironment.demo;
1113

14+
@JS('removeSplashFromWeb')
15+
external void removeSplashFromWeb();
16+
1217
void main() async {
1318
final appConfig = switch (currentEnvironment) {
1419
AppEnvironment.production => AppConfig.production(),
@@ -18,13 +23,17 @@ void main() async {
1823

1924
final appWidget = await bootstrap(appConfig);
2025

26+
// Only remove the splash screen on web after the app is ready.
27+
if (kIsWeb) {
28+
removeSplashFromWeb();
29+
}
30+
2131
if (appConfig.environment == AppEnvironment.demo) {
2232
runApp(
2333
DevicePreview(
2434
enabled: true,
2535
builder: (context) => appWidget,
2636
tools: const [DeviceSection()],
27-
2837
),
2938
);
3039
} else {

pubspec.lock

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,18 @@ packages:
501501
dependency: transitive
502502
description:
503503
name: js
504-
sha256: "53385261521cc4a0c4658fd0ad07a7d14591cf8fc33abbceae306ddb974888dc"
504+
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
505505
url: "https://pub.dev"
506506
source: hosted
507-
version: "0.7.2"
507+
version: "0.6.7"
508+
js_interop:
509+
dependency: "direct main"
510+
description:
511+
name: js_interop
512+
sha256: "7ec859c296958ccea34dc770504bd3ff4ae52fdd9e7eeb2bacc7081ad476a1f5"
513+
url: "https://pub.dev"
514+
source: hosted
515+
version: "0.0.1"
508516
json_annotation:
509517
dependency: transitive
510518
description:

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ dependencies:
5757
git:
5858
url: https://github.com/headlines-toolkit/ht-shared.git
5959
intl: ^0.20.2
60+
js_interop: ^0.0.1
6061
meta: ^1.16.0
6162
share_plus: ^11.0.0
6263
stream_transform: ^2.1.1

web/index.html

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
<link rel="manifest" href="manifest.json">
3232
<style id="splash-screen-style">
3333
html {
34-
height: 100%
34+
height: 100%;
3535
}
3636

3737
body {
3838
margin: 0;
3939
min-height: 100%;
4040
background-color: #FFFFFF;
41-
background-size: 100% 100%;
41+
background-size: 100% 100%;
4242
}
4343

4444
.center {
@@ -51,19 +51,22 @@
5151
}
5252

5353
.contain {
54-
display:block;
55-
width:100%; height:100%;
54+
display: block;
55+
width: 100%;
56+
height: 100%;
5657
object-fit: contain;
5758
}
5859

5960
.stretch {
60-
display:block;
61-
width:100%; height:100%;
61+
display: block;
62+
width: 100%;
63+
height: 100%;
6264
}
6365

6466
.cover {
65-
display:block;
66-
width:100%; height:100%;
67+
display: block;
68+
width: 100%;
69+
height: 100%;
6770
object-fit: cover;
6871
}
6972

@@ -90,22 +93,61 @@
9093
@media (prefers-color-scheme: dark) {
9194
body {
9295
background-color: #212121;
93-
}
96+
}
97+
}
98+
99+
/* Styles for the loading indicator */
100+
#loading-indicator {
101+
position: fixed;
102+
top: 0;
103+
left: 0;
104+
width: 100%;
105+
height: 100%;
106+
background-color: #FFFFFF; /* Match body background */
107+
display: flex;
108+
justify-content: center;
109+
align-items: center;
110+
z-index: 9999; /* Ensure it's on top */
111+
}
112+
113+
@media (prefers-color-scheme: dark) {
114+
#loading-indicator {
115+
background-color: #212121; /* Match dark mode body background */
116+
}
117+
}
118+
119+
/* Simple spinner animation */
120+
.spinner {
121+
border: 4px solid rgba(0, 0, 0, 0.1);
122+
border-left-color: #0175C2; /* Use theme color from manifest */
123+
border-radius: 50%;
124+
width: 50px;
125+
height: 50px;
126+
animation: spin 1s linear infinite;
127+
}
128+
129+
@keyframes spin {
130+
0% { transform: rotate(0deg); }
131+
100% { transform: rotate(360deg); }
94132
}
95133
</style>
96134
<script id="splash-screen-script">
97135
function removeSplashFromWeb() {
98136
document.getElementById("splash")?.remove();
99137
document.getElementById("splash-branding")?.remove();
138+
document.getElementById("loading-indicator")?.remove(); // Remove the new loading indicator
100139
document.body.style.background = "transparent";
101140
}
102141
</script>
103142
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
104143
</head>
105144
<body>
145+
<div id="loading-indicator">
146+
<div class="spinner"></div>
147+
</div>
106148
<script>
107149
{{flutter_bootstrap_js}}
108150
</script>
109151

110152

111-
</body></html>
153+
</body></html>

0 commit comments

Comments
 (0)