convert mih web app from JS to WASm
This commit is contained in:
parent
eb213b01b6
commit
f9c71b656e
17 changed files with 78 additions and 127 deletions
|
|
@ -18,7 +18,6 @@ import 'package:mzansi_innovation_hub/mih_objects/business_user.dart';
|
|||
import 'package:mzansi_innovation_hub/mih_objects/loyalty_card.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/profile_link.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/user_consent.dart';
|
||||
import 'package:pwa_install/pwa_install.dart';
|
||||
import 'mih_config/mih_env.dart';
|
||||
import 'package:supertokens_flutter/supertokens.dart';
|
||||
import 'package:hive_ce_flutter/hive_ce_flutter.dart';
|
||||
|
|
@ -70,9 +69,6 @@ void main() async {
|
|||
} else {
|
||||
usePathUrlStrategy();
|
||||
}
|
||||
PWAInstall().setup(installCallback: () {
|
||||
debugPrint('APP INSTALLED!');
|
||||
});
|
||||
final GoRouter appRouter = MihGoRouter().mihRouter;
|
||||
runApp(MzansiInnovationHub(
|
||||
router: appRouter,
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ import 'package:mzansi_innovation_hub/mih_objects/business_user.dart';
|
|||
import 'package:mzansi_innovation_hub/mih_objects/loyalty_card.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/profile_link.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/user_consent.dart';
|
||||
import 'package:pwa_install/pwa_install.dart';
|
||||
import 'mih_config/mih_env.dart';
|
||||
import 'package:supertokens_flutter/supertokens.dart';
|
||||
import 'package:hive_ce_flutter/hive_ce_flutter.dart';
|
||||
|
|
@ -70,9 +69,6 @@ void main() async {
|
|||
} else {
|
||||
usePathUrlStrategy();
|
||||
}
|
||||
PWAInstall().setup(installCallback: () {
|
||||
debugPrint('APP INSTALLED!');
|
||||
});
|
||||
final GoRouter appRouter = MihGoRouter().mihRouter;
|
||||
runApp(MzansiInnovationHub(
|
||||
router: appRouter,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:mih_package_toolkit/mih_package_toolkit.dart';
|
||||
import "package:universal_html/html.dart" as html;
|
||||
import 'package:mzansi_innovation_hub/mih_helpers/mih_utils_stub.dart'
|
||||
if (dart.library.js_interop) 'package:mzansi_innovation_hub/mih_helpers/mih_utils_web.dart';
|
||||
|
||||
class MihTheme {
|
||||
late String mode;
|
||||
|
|
@ -107,7 +108,7 @@ class MihTheme {
|
|||
}
|
||||
|
||||
bool isPwa() {
|
||||
return html.window.matchMedia('(display-mode: standalone)').matches;
|
||||
return isWebStandalone();
|
||||
}
|
||||
|
||||
void setMode(String m) {
|
||||
|
|
|
|||
3
mih_ui/lib/mih_helpers/mih_install_stub.dart
Normal file
3
mih_ui/lib/mih_helpers/mih_install_stub.dart
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
void triggerWebInstall() {
|
||||
// Safe no-op on Linux/Mobile
|
||||
}
|
||||
13
mih_ui/lib/mih_helpers/mih_install_web.dart
Normal file
13
mih_ui/lib/mih_helpers/mih_install_web.dart
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import 'dart:js_interop';
|
||||
|
||||
@JS('promptInstall')
|
||||
external void jsPromptInstall();
|
||||
|
||||
@JS('isInstallPromptAvailable')
|
||||
external bool jsIsInstallPromptAvailable();
|
||||
|
||||
void triggerWebInstall() {
|
||||
if (jsIsInstallPromptAvailable()) {
|
||||
jsPromptInstall();
|
||||
}
|
||||
}
|
||||
8
mih_ui/lib/mih_helpers/mih_utils_stub.dart
Normal file
8
mih_ui/lib/mih_helpers/mih_utils_stub.dart
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// Create this file anywhere, e.g., lib/mih_config/mih_web_utils_stub.dart
|
||||
void openWebWindow(String url, [String? target]) {
|
||||
// Safe no-op or fallback on Linux (e.g., could use url_launcher if needed)
|
||||
}
|
||||
|
||||
bool isWebStandalone() {
|
||||
return false; // Always false on native Linux app
|
||||
}
|
||||
13
mih_ui/lib/mih_helpers/mih_utils_web.dart
Normal file
13
mih_ui/lib/mih_helpers/mih_utils_web.dart
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import 'package:web/web.dart' as web;
|
||||
|
||||
void openWebWindow(String url, [String? target]) {
|
||||
if (target != null) {
|
||||
web.window.open(url, target);
|
||||
} else {
|
||||
web.window.open(url);
|
||||
}
|
||||
}
|
||||
|
||||
bool isWebStandalone() {
|
||||
return web.window.matchMedia('(display-mode: standalone)').matches;
|
||||
}
|
||||
|
|
@ -58,10 +58,13 @@ class _MihSignInState extends State<MihSignIn> {
|
|||
void submitSignInForm() async {
|
||||
await signUserIn();
|
||||
if (successfulSignIn) {
|
||||
TextInput.finishAutofillContext();
|
||||
context.goNamed(
|
||||
'mihHome',
|
||||
extra: true,
|
||||
);
|
||||
} else {
|
||||
TextInput.finishAutofillContext(shouldSave: false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ import 'package:mzansi_innovation_hub/mih_providers/mih_file_viewer_provider.dar
|
|||
import 'package:provider/provider.dart';
|
||||
import 'package:syncfusion_flutter_core/theme.dart';
|
||||
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
|
||||
import "package:universal_html/html.dart" as html;
|
||||
import 'package:mzansi_innovation_hub/mih_helpers/mih_utils_stub.dart'
|
||||
if (dart.library.js_interop) 'package:mzansi_innovation_hub/mih_helpers/mih_utils_web.dart';
|
||||
import 'package:fl_downloader/fl_downloader.dart';
|
||||
|
||||
class MihExpandedFileView extends StatefulWidget {
|
||||
|
|
@ -227,7 +228,7 @@ class _MihExpandedFileViewState extends State<MihExpandedFileView> {
|
|||
padding: const EdgeInsets.all(0),
|
||||
onPressed: () {
|
||||
if (kIsWeb) {
|
||||
html.window.open(
|
||||
openWebWindow(
|
||||
fileViewerProvider.fileLink, 'download');
|
||||
} else {
|
||||
nativeFileDownload(
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ import 'package:flutter/material.dart';
|
|||
import 'package:provider/provider.dart';
|
||||
import 'package:supertokens_flutter/http.dart' as http;
|
||||
import 'package:http/http.dart' as http2;
|
||||
import "package:universal_html/html.dart" as html;
|
||||
import 'package:mzansi_innovation_hub/mih_helpers/mih_utils_stub.dart'
|
||||
if (dart.library.js_interop) 'package:mzansi_innovation_hub/mih_helpers/mih_utils_web.dart';
|
||||
|
||||
class BuildClaimStatementFileList extends StatefulWidget {
|
||||
const BuildClaimStatementFileList({
|
||||
|
|
@ -110,7 +111,7 @@ class _BuildClaimStatementFileListState
|
|||
backgroundColor: MihColors.green(),
|
||||
onTap: () {
|
||||
if (MzansiInnovationHub.of(context)!.theme.getPlatform() == "Web") {
|
||||
html.window.open(url, 'download');
|
||||
openWebWindow(url, 'download');
|
||||
} else {
|
||||
nativeFileDownload(url);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ import 'package:flutter/material.dart';
|
|||
import 'package:provider/provider.dart';
|
||||
import 'package:supertokens_flutter/http.dart' as http;
|
||||
import 'package:http/http.dart' as http2;
|
||||
import "package:universal_html/html.dart" as html;
|
||||
import 'package:mzansi_innovation_hub/mih_helpers/mih_utils_stub.dart'
|
||||
if (dart.library.js_interop) 'package:mzansi_innovation_hub/mih_helpers/mih_utils_web.dart';
|
||||
|
||||
class BuildFilesList extends StatefulWidget {
|
||||
const BuildFilesList({
|
||||
|
|
@ -103,7 +104,7 @@ class _BuildFilesListState extends State<BuildFilesList> {
|
|||
backgroundColor: MihColors.green(),
|
||||
onTap: () {
|
||||
if (MzansiInnovationHub.of(context)!.theme.getPlatform() == "Web") {
|
||||
html.window.open(url, 'download');
|
||||
openWebWindow(url, 'download');
|
||||
} else {
|
||||
nativeFileDownload(url);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:mih_package_toolkit/mih_package_toolkit.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
|
||||
|
|
@ -59,6 +60,7 @@ class MihAuthenticationServices {
|
|||
if (response2.statusCode == 200) {
|
||||
var userCreated = jsonDecode(response2.body);
|
||||
if (userCreated["status"] == "OK") {
|
||||
TextInput.finishAutofillContext();
|
||||
String uid = await SuperTokens.getUserId();
|
||||
await MihUserServices().createUser(
|
||||
email,
|
||||
|
|
@ -72,6 +74,7 @@ class MihAuthenticationServices {
|
|||
} else {
|
||||
context.pop();
|
||||
MihAlertServices().internetConnectionAlert(context);
|
||||
TextInput.finishAutofillContext(shouldSave: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:pwa_install/pwa_install.dart';
|
||||
// import 'package:universal_html/js.dart' as js;
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_helpers/mih_install_stub.dart'
|
||||
if (dart.library.js_interop) 'package:mzansi_innovation_hub/mih_helpers/mih_install_web.dart';
|
||||
|
||||
class MihInstallServices {
|
||||
String? errorMessage;
|
||||
|
|
@ -45,20 +45,11 @@ class MihInstallServices {
|
|||
"https://apps.apple.com/za/app/mzansi-innovation-hub/id6743310890",
|
||||
),
|
||||
);
|
||||
} else if (MzansiInnovationHub.of(context)!.theme.getPlatform() ==
|
||||
"Linux") {
|
||||
} else {
|
||||
//Web
|
||||
if (PWAInstall().installPromptEnabled) {
|
||||
try {
|
||||
PWAInstall().promptInstall_();
|
||||
} catch (e) {
|
||||
errorMessage = e.toString();
|
||||
debugPrint('Error prompting install: $e');
|
||||
}
|
||||
} else {
|
||||
// Fallback for unsupported platforms
|
||||
debugPrint('Install prompt not available for this platform.');
|
||||
}
|
||||
// js.context.callMethod("presentAddToHome");
|
||||
triggerWebInstall();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue