This commit is contained in:
Hamza-Ayed
2025-02-01 18:33:44 +03:00
parent 13a7c3db81
commit b11c999bcc
4 changed files with 75 additions and 0 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.2 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 8.6 KiB

View File

@@ -0,0 +1,57 @@
// import 'package:home_widget/home_widget.dart';
// class TripzHomeWidgetProvider {
// static const String widgetName = 'TripzHomeWidget';
// // Initialize Home Widget
// static Future<void> initHomeWidget() async {
// await HomeWidget.registerInteractivityCallback(backgroundCallback);
// }
// // Background Callback for Widget Updates
// static Future<void> backgroundCallback(Uri? uri) async {
// if (uri?.host == 'updateWidget') {
// // Logic to update widget data
// await updateWidgetData();
// }
// }
// // Update Widget Data Method
// static Future<void> updateWidgetData() async {
// // Fetch current ride details
// final rideData = await _fetchCurrentRideDetails();
// // Update Widget with Ride Information
// await HomeWidget.saveWidgetData<String>(
// 'ride_destination', rideData.destination);
// await HomeWidget.saveWidgetData<String>(
// 'ride_estimated_time', rideData.estimatedTime);
// await HomeWidget.saveWidgetData<double>('ride_fare', rideData.fare);
// // Trigger Widget Update
// await HomeWidget.updateWidget(
// name: widgetName,
// iOSName: 'TripzWidgetProvider',
// androidName: 'com.mobileapp.store.ride.HomeWidgetProvider',
// );
// }
// // Mock method to fetch ride details (replace with actual implementation)
// static Future<RideData> _fetchCurrentRideDetails() async {
// // Implement actual data fetching logic
// return RideData(
// destination: 'Downtown Office', estimatedTime: '25 mins', fare: 15.50);
// }
// }
// // Ride Data Model
// class RideData {
// final String destination;
// final String estimatedTime;
// final double fare;
// RideData(
// {required this.destination,
// required this.estimatedTime,
// required this.fare});
// }

18
lib/homw_widget.dart Normal file
View File

@@ -0,0 +1,18 @@
import 'package:flutter/services.dart';
class WidgetManager {
static const platform = MethodChannel('com.mobileapp.store.ride/widget');
static Future<void> updateWidget() async {
try {
await platform.invokeMethod('updateWidget');
} on PlatformException catch (e) {
print("Failed to update widget: '${e.message}'.");
}
}
}
// Example usage:
void updateHomeScreenWidget() {
WidgetManager.updateWidget();
}