fix platform specific code not working on web
This commit is contained in:
@@ -20,7 +20,15 @@ abstract class AppEnviroment {
|
||||
switch (env) {
|
||||
case Enviroment.dev:
|
||||
{
|
||||
if (kIsWeb || Platform.isIOS || Platform.isLinux) {
|
||||
if (kIsWeb) {
|
||||
//================= 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'; // IOS ID
|
||||
break;
|
||||
} else if (Platform.isIOS || Platform.isLinux) {
|
||||
//================= Web Dev Urls =================
|
||||
baseAppUrl = "http://localhost:80";
|
||||
baseApiUrl = "http://localhost:8080";
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:country_code_picker/country_code_picker.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
@@ -453,7 +454,8 @@ class _PackageToolOneState extends State<PackageToolOne> {
|
||||
),
|
||||
],
|
||||
),
|
||||
if (Platform.isAndroid || Platform.isIOS) MihBannerAd(),
|
||||
if (!kIsWeb && (Platform.isAndroid || Platform.isIOS))
|
||||
MihBannerAd(),
|
||||
const SizedBox(height: 10),
|
||||
Divider(
|
||||
color: MihColors.getSecondaryColor(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:ken_logger/ken_logger.dart';
|
||||
@@ -101,7 +102,7 @@ class _MihPackageState extends State<MihPackage>
|
||||
// _peakAnimation();
|
||||
// });
|
||||
// }
|
||||
if (Platform.isAndroid || Platform.isIOS) {
|
||||
if (!kIsWeb && Platform.isAndroid || Platform.isIOS) {
|
||||
// Trigger the peak animation only AFTER the route transition is complete
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
final ModalRoute? currentRoute = ModalRoute.of(context);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
@@ -159,7 +160,7 @@ class _CurrencyExchangeRateState extends State<CurrencyExchangeRate> {
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
Consumer(builder: (context, bannerAdDisplay, child) {
|
||||
if (Platform.isAndroid || Platform.isIOS) {
|
||||
if (!kIsWeb && (Platform.isAndroid || Platform.isIOS)) {
|
||||
return MihBannerAd();
|
||||
} else {
|
||||
return const SizedBox(height: 0);
|
||||
|
||||
@@ -231,7 +231,7 @@ class _TipCalcState extends State<TipCalc> {
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
Consumer(builder: (context, bannerAdDisplay, child) {
|
||||
if (Platform.isAndroid || Platform.isIOS) {
|
||||
if (!kIsWeb && (Platform.isAndroid || Platform.isIOS)) {
|
||||
return MihBannerAd();
|
||||
} else {
|
||||
return const SizedBox(height: 0);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
@@ -852,7 +853,7 @@ class _MineSweeperGameState extends State<MineSweeperGame> {
|
||||
],
|
||||
),
|
||||
),
|
||||
_timer != null && (Platform.isAndroid || Platform.isIOS)
|
||||
_timer != null && !kIsWeb && (Platform.isAndroid || Platform.isIOS)
|
||||
? MihBannerAd()
|
||||
: SizedBox(),
|
||||
SizedBox(height: 15),
|
||||
|
||||
@@ -129,7 +129,7 @@ class _MihAiChatState extends State<MihAiChat> with WidgetsBindingObserver {
|
||||
}
|
||||
|
||||
if (textToSpeak != null) {
|
||||
if (Platform.isLinux) {
|
||||
if (!kIsWeb && Platform.isLinux) {
|
||||
// Linux Workaround: Use Speech Dispatcher (standard on most distros)
|
||||
// '-t female1' is optional for voice variety
|
||||
Process.run('spd-say', [textToSpeak]);
|
||||
@@ -204,7 +204,7 @@ class _MihAiChatState extends State<MihAiChat> with WidgetsBindingObserver {
|
||||
// }
|
||||
|
||||
void stopTTS(MzansiAiProvider aiProvider) {
|
||||
if (Platform.isLinux) {
|
||||
if (!kIsWeb && Platform.isLinux) {
|
||||
Process.run('spd-say', ['-S']); // The -S flag stops current speech
|
||||
} else {
|
||||
_flutterTts.stop();
|
||||
@@ -213,7 +213,7 @@ class _MihAiChatState extends State<MihAiChat> with WidgetsBindingObserver {
|
||||
}
|
||||
|
||||
Future<void> initTts(MzansiAiProvider aiProvider) async {
|
||||
if (Platform.isLinux) return;
|
||||
if (!kIsWeb && Platform.isLinux) return;
|
||||
try {
|
||||
await _flutterTts.setSpeechRate(!kIsWeb ? 0.55 : 1);
|
||||
// await _flutterTts.setLanguage("en-US");
|
||||
@@ -284,7 +284,7 @@ class _MihAiChatState extends State<MihAiChat> with WidgetsBindingObserver {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
if (!Platform.isLinux) {
|
||||
if (!kIsWeb && !Platform.isLinux) {
|
||||
_flutterTts.stop();
|
||||
}
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
|
||||
@@ -547,7 +547,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
if (Platform.isAndroid || Platform.isIOS) MihBannerAd()
|
||||
if (!kIsWeb && (Platform.isAndroid || Platform.isIOS)) MihBannerAd()
|
||||
// MihBannerAd(),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -30,7 +30,7 @@ class MihBannerAdProvider extends ChangeNotifier {
|
||||
}
|
||||
|
||||
void loadBannerAd() {
|
||||
if (Platform.isAndroid || Platform.isIOS) {
|
||||
if (!kIsWeb && (Platform.isAndroid || Platform.isIOS)) {
|
||||
if (bannerAd != null) {
|
||||
bannerAd!.dispose();
|
||||
bannerAd = null;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
@@ -136,7 +137,7 @@ class MihAlertServices {
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
Text(
|
||||
Platform.isLinux
|
||||
!kIsWeb && 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(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
|
||||
@@ -16,7 +17,7 @@ class MIHLocationAPI {
|
||||
///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) {
|
||||
if (!serviceEnabled && !kIsWeb && Platform.isLinux) {
|
||||
// Direct the user to their System Settings
|
||||
MihAlertServices().locationPermissionAlert(context);
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user