99 lines
2.4 KiB
Dart
99 lines
2.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:trip_overlay_plugin/trip_overlay_plugin.dart';
|
|
|
|
void main() {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
TripOverlayPlugin.initialize();
|
|
runApp(const MyApp());
|
|
}
|
|
|
|
class MyApp extends StatefulWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
State<MyApp> createState() => _MyAppState();
|
|
}
|
|
|
|
class _MyAppState extends State<MyApp> {
|
|
bool _isOverlayActive = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
// Listen to overlay events
|
|
TripOverlayPlugin.onTripAccepted.listen((result) {
|
|
debugPrint('Trip accepted: ${result.tripId}');
|
|
});
|
|
TripOverlayPlugin.onTripRejected.listen((tripId) {
|
|
debugPrint('Trip rejected/expired: $tripId');
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
TripOverlayPlugin.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
Future<void> _showOverlay() async {
|
|
final granted = await TripOverlayPlugin.isPermissionGranted();
|
|
if (!granted) {
|
|
await TripOverlayPlugin.requestPermission();
|
|
return;
|
|
}
|
|
|
|
final tripData = TripData(
|
|
tripId: 'TRIP_12345',
|
|
passengerName: 'Hamza A.',
|
|
pickupAddress: 'Amman, Jordan',
|
|
dropoffAddress: 'Irbid, Jordan',
|
|
distanceKm: 85.0,
|
|
estimatedFare: 25.0,
|
|
estimatedMinutes: 90,
|
|
pickupLat: 31.9539,
|
|
pickupLng: 35.9106,
|
|
);
|
|
|
|
final result = await TripOverlayPlugin.showOverlay(tripData);
|
|
setState(() {
|
|
_isOverlayActive = result;
|
|
});
|
|
}
|
|
|
|
Future<void> _hideOverlay() async {
|
|
await TripOverlayPlugin.hideOverlay();
|
|
setState(() {
|
|
_isOverlayActive = false;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
home: Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Trip Overlay Example'),
|
|
),
|
|
body: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Text('Overlay Active: $_isOverlayActive'),
|
|
const SizedBox(height: 20),
|
|
ElevatedButton(
|
|
onPressed: _showOverlay,
|
|
child: const Text('Show Overlay'),
|
|
),
|
|
const SizedBox(height: 10),
|
|
ElevatedButton(
|
|
onPressed: _hideOverlay,
|
|
child: const Text('Hide Overlay'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|