Support linux version of MIH

This commit is contained in:
2026-02-24 15:41:55 +02:00
parent ce2575035f
commit 6ad6b6ccbd
10 changed files with 81 additions and 18 deletions

View File

@@ -20,13 +20,13 @@ abstract class AppEnviroment {
switch (env) {
case Enviroment.dev:
{
if (kIsWeb) {
if (kIsWeb || Platform.isIOS || Platform.isLinux) {
//================= Web Dev Urls =================
baseAppUrl = "http://localhost:80";
baseApiUrl = "http://localhost:8080";
baseFileUrl = "http://localhost:9000";
baseAiUrl = "http://localhost:11434";
bannerAdUnitId = 'ca-app-pub-3940256099942544/2435281174';
bannerAdUnitId = 'ca-app-pub-3940256099942544/2435281174'; // IOS ID
break;
} else if (Platform.isAndroid) {
//================= Android Dev Urls =================
@@ -35,14 +35,6 @@ abstract class AppEnviroment {
baseFileUrl = "http://10.0.2.2:9000";
baseAiUrl = "http://10.0.2.2:11434";
bannerAdUnitId = 'ca-app-pub-3940256099942544/9214589741';
} else {
//================= Web & iOS Dev Urls =================
baseAppUrl = "http://localhost:80";
baseApiUrl = "http://localhost:8080";
baseFileUrl = "http://localhost:9000";
baseAiUrl = "http://localhost:11434";
bannerAdUnitId = 'ca-app-pub-3940256099942544/2435281174';
break;
}
}
case Enviroment.prod:

View File

@@ -98,6 +98,12 @@ class MihTheme {
return "Android";
} else if (platform == TargetPlatform.iOS) {
return "iOS";
} else if (platform == TargetPlatform.linux) {
return "Linux";
} else if (platform == TargetPlatform.macOS) {
return "macOS";
} else if (platform == TargetPlatform.windows) {
return "Windows";
}
}
return "Other";

View File

@@ -1,7 +1,8 @@
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:go_router/go_router.dart';
import 'package:ken_logger/ken_logger.dart';
import 'package:mzansi_innovation_hub/main.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_scack_bar.dart';
import 'package:mzansi_innovation_hub/mih_packages/mih_home/components/mih_app_drawer.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_package_tools.dart';
@@ -100,7 +101,7 @@ class _MihPackageState extends State<MihPackage>
// _peakAnimation();
// });
// }
if (!MzansiInnovationHub.of(context)!.theme.kIsWeb) {
if (Platform.isAndroid || Platform.isIOS) {
// Trigger the peak animation only AFTER the route transition is complete
WidgetsBinding.instance.addPostFrameCallback((_) {
final ModalRoute? currentRoute = ModalRoute.of(context);

View File

@@ -1,3 +1,5 @@
import 'dart:io';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:file_picker/file_picker.dart';
import 'package:file_saver/file_saver.dart';
@@ -82,6 +84,19 @@ class _MihBusinessQrCodeState extends State<MihBusinessQrCode> {
fileExtension: "png",
mimeType: MimeType.png,
);
} else if (defaultTargetPlatform == TargetPlatform.linux ||
defaultTargetPlatform == TargetPlatform.windows) {
// Use File Picker to get a save path on Desktop
String? outputFile = await FilePicker.platform.saveFile(
dialogTitle: 'Please select where to save your QR Code:',
fileName: filename,
);
if (outputFile != null) {
final file = File(outputFile);
await file.writeAsBytes(imageBytes);
KenLogger.success("Saved to $outputFile");
}
} else {
await FileSaver.instance.saveAs(
name: filename,
@@ -95,14 +110,14 @@ class _MihBusinessQrCodeState extends State<MihBusinessQrCode> {
Future<void> downloadQrCode() async {
if (_isUserSignedIn) {
await screenshotController.capture().then((image) {
KenLogger.success("Image Captured: $image");
// KenLogger.success("Image Captured: $image");
setState(() {
businessQRImageFile = image;
});
}).catchError((onError) {
KenLogger.error(onError);
});
KenLogger.success("QR Code Image Captured : $businessQRImageFile");
// KenLogger.success("QR Code Image Captured : $businessQRImageFile");
saveImage(businessQRImageFile!);
} else {
showSignInRequiredAlert();

View File

@@ -1,3 +1,5 @@
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
import 'package:go_router/go_router.dart';
@@ -545,7 +547,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
),
),
SizedBox(height: 10),
MihBannerAd()
if (Platform.isAndroid || Platform.isIOS) MihBannerAd()
// MihBannerAd(),
],
),
@@ -572,7 +574,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
}
Future<void> setScreenBrightness(double newBrightness) async {
if (!kIsWeb) {
if (!kIsWeb && !Platform.isLinux) {
bool canChange =
await ScreenBrightness.instance.canChangeSystemBrightness;

View File

@@ -1,3 +1,5 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:mzansi_innovation_hub/main.dart';
@@ -134,7 +136,9 @@ class MihAlertServices {
),
const SizedBox(height: 15),
Text(
"To get the most out of MIH, we need your location. Please go to the site settings of the app and enable location services. Once you do that, we can start showing you relevant information based on your location.",
Platform.isLinux
? "To get the most out of MIH, we need your location. Please go to your System Settings and enable location services. Once you do that, we can start showing you relevant information based on your location."
: "To get the most out of MIH, we need your location. Please go to the site settings of the app and enable location services. Once you do that, we can start showing you relevant information based on your location.",
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==

View File

@@ -55,10 +55,12 @@ class MihFileApi {
// Navigator.of(context).pop(); // Always pop loading dialog
}
KenLogger.success("File URL: $fileUrl");
if (AppEnviroment.getEnv() == "Dev" && isSkiaWeb) {
if (AppEnviroment.getEnv() == "Dev" && kIsWeb) {
fileUrl = fileUrl.replaceAll("10.0.2.2", "127.0.0.1");
} else if (AppEnviroment.getEnv() == "Dev" && Platform.isIOS) {
fileUrl = fileUrl.replaceAll("10.0.2.2", "127.0.0.1");
} else if (AppEnviroment.getEnv() == "Dev" && Platform.isLinux) {
fileUrl = fileUrl.replaceAll("10.0.2.2", "127.0.0.1");
}
KenLogger.success("File URL: $fileUrl");
return fileUrl;

View File

@@ -1,3 +1,5 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
@@ -13,6 +15,12 @@ class MIHLocationAPI {
///if user has blocked permission (denied or denied forver), user will get error pop up.
///if user has granted permission (while in use), function will return Position object.
Future<Position?> getGPSPosition(BuildContext context) async {
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled && Platform.isLinux) {
// Direct the user to their System Settings
MihAlertServices().locationPermissionAlert(context);
return null;
}
print("Before checkPermission"); // Debug
LocationPermission permission = await Geolocator.checkPermission();
print("After checkPermission: $permission"); // Debug