fixing android build
This commit is contained in:
14
lib/browser.dart
Normal file
14
lib/browser.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
/// Platform-aware browser API abstraction.
|
||||
///
|
||||
/// On web, provides real browser localStorage and location APIs.
|
||||
/// On non-web platforms (Android, iOS, desktop), returns no-op stubs.
|
||||
///
|
||||
/// Usage:
|
||||
/// ```dart
|
||||
/// import 'package:qpay/browser.dart';
|
||||
/// Browser.localStorage.setItem('key', 'value');
|
||||
/// Browser.localStorage.getItem('key');
|
||||
/// Browser.location.href = 'https://example.com';
|
||||
/// ```
|
||||
export 'platform/browser_stub.dart'
|
||||
if (dart.library.html) 'platform/browser_web.dart';
|
||||
@@ -1,8 +1,9 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:qpay/auth_state.dart';
|
||||
import 'package:qpay/routes.dart';
|
||||
import 'package:qpay/url_strategy.dart';
|
||||
import 'package:qpay/screens/transaction_controller.dart';
|
||||
import 'package:qpay/screens/onboarding/onboarding_controller.dart';
|
||||
import 'package:qpay/theme/app_theme.dart';
|
||||
@@ -26,7 +27,9 @@ String resolveEnvFile(String env) {
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
usePathUrlStrategy();
|
||||
if (kIsWeb) {
|
||||
usePathUrlStrategy();
|
||||
}
|
||||
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
||||
|
||||
await dotenv.load(fileName: resolveEnvFile(appEnv));
|
||||
@@ -70,4 +73,4 @@ class _MyAppState extends State<MyApp> {
|
||||
routerConfig: buildRouter(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
lib/platform/browser_stub.dart
Normal file
18
lib/platform/browser_stub.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
/// Stub implementation of browser APIs for non-web platforms.
|
||||
class BrowserStorage {
|
||||
String? getItem(String key) => null;
|
||||
void setItem(String key, String value) {}
|
||||
void removeItem(String key) {}
|
||||
}
|
||||
|
||||
/// Stub for window.location
|
||||
class BrowserLocation {
|
||||
String get href => '';
|
||||
set href(String value) {}
|
||||
}
|
||||
|
||||
/// Browser utility class for non-web platforms.
|
||||
class Browser {
|
||||
static final BrowserStorage localStorage = BrowserStorage();
|
||||
static final BrowserLocation location = BrowserLocation();
|
||||
}
|
||||
22
lib/platform/browser_web.dart
Normal file
22
lib/platform/browser_web.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
import 'package:web/web.dart' as web;
|
||||
|
||||
/// Web implementation of browser APIs using package:web.
|
||||
class BrowserStorage {
|
||||
String? getItem(String key) => web.window.localStorage.getItem(key);
|
||||
void setItem(String key, String value) =>
|
||||
web.window.localStorage.setItem(key, value);
|
||||
void removeItem(String key) =>
|
||||
web.window.localStorage.removeItem(key);
|
||||
}
|
||||
|
||||
/// Web implementation for window.location
|
||||
class BrowserLocation {
|
||||
String get href => web.window.location.href;
|
||||
set href(String value) => web.window.location.href = value;
|
||||
}
|
||||
|
||||
/// Browser utility class using package:web.
|
||||
class Browser {
|
||||
static final BrowserStorage localStorage = BrowserStorage();
|
||||
static final BrowserLocation location = BrowserLocation();
|
||||
}
|
||||
3
lib/platform/url_strategy_stub.dart
Normal file
3
lib/platform/url_strategy_stub.dart
Normal file
@@ -0,0 +1,3 @@
|
||||
/// Stub for path URL strategy on non-web platforms.
|
||||
/// Does nothing since URL strategies are web-only.
|
||||
void usePathUrlStrategy() {}
|
||||
6
lib/platform/url_strategy_web.dart
Normal file
6
lib/platform/url_strategy_web.dart
Normal file
@@ -0,0 +1,6 @@
|
||||
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
|
||||
|
||||
/// Web implementation that sets the path URL strategy.
|
||||
void usePathUrlStrategy() {
|
||||
flutter_web_plugins.usePathUrlStrategy();
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:qpay/models/responsive_policy.dart';
|
||||
import 'package:qpay/screens/gateway/gateway_controller.dart';
|
||||
import 'package:web/web.dart' as web;
|
||||
import 'package:qpay/browser.dart';
|
||||
|
||||
class GatewayWebScreen extends StatefulWidget {
|
||||
const GatewayWebScreen({super.key});
|
||||
@@ -50,7 +50,7 @@ class _GatewayWebScreenState extends State<GatewayWebScreen> {
|
||||
final transactionId =
|
||||
controller.transactionController.model.confirmationData['id'];
|
||||
if (transactionId != null) {
|
||||
web.window.localStorage.setItem(
|
||||
Browser.localStorage.setItem(
|
||||
'pendingTransactionId',
|
||||
transactionId.toString(),
|
||||
);
|
||||
@@ -60,7 +60,7 @@ class _GatewayWebScreenState extends State<GatewayWebScreen> {
|
||||
// After payment, the gateway will redirect back to this app's host.
|
||||
// index.html then reads the saved transaction ID and navigates to
|
||||
// /poll/:id so the app can immediately start polling for the result.
|
||||
web.window.location.href = url;
|
||||
Browser.location.href = url;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -5,7 +5,7 @@ import 'package:provider/provider.dart';
|
||||
import 'package:qpay/screens/gateway/gateway_controller.dart';
|
||||
import 'package:qpay/screens/transaction_controller.dart';
|
||||
import 'package:qpay/widgets/step_loading_widget.dart';
|
||||
import 'package:web/web.dart' as web;
|
||||
import 'package:qpay/browser.dart';
|
||||
|
||||
class PollScreen extends StatefulWidget {
|
||||
final String? transactionId;
|
||||
@@ -39,8 +39,8 @@ class _PollScreenState extends State<PollScreen> {
|
||||
// Priority 2: localStorage (for when gateway redirect causes page reload
|
||||
// and the route param path is not available due to hub redirect override)
|
||||
if (transactionId == null && kIsWeb) {
|
||||
transactionId = web.window.localStorage.getItem('pendingTransactionId');
|
||||
web.window.localStorage.removeItem('pendingTransactionId');
|
||||
transactionId = Browser.localStorage.getItem('pendingTransactionId');
|
||||
Browser.localStorage.removeItem('pendingTransactionId');
|
||||
}
|
||||
|
||||
// Priority 3: in-memory confirmation data (normal SPA navigation)
|
||||
|
||||
6
lib/url_strategy.dart
Normal file
6
lib/url_strategy.dart
Normal file
@@ -0,0 +1,6 @@
|
||||
/// Platform-aware path URL strategy.
|
||||
///
|
||||
/// On web, sets the path URL strategy via [usePathUrlStrategy].
|
||||
/// On non-web platforms, this is a no-op.
|
||||
export 'platform/url_strategy_stub.dart'
|
||||
if (dart.library.html) 'platform/url_strategy_web.dart';
|
||||
Reference in New Issue
Block a user