Files
tripz/lib/controller/firebase/live_activity.dart
Hamza-Ayed 13a7c3db81 25-1/31/1
2025-01-31 14:57:17 +03:00

60 lines
1.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class LiveActivityScreen extends StatefulWidget {
@override
_LiveActivityScreenState createState() => _LiveActivityScreenState();
}
class _LiveActivityScreenState extends State<LiveActivityScreen> {
static const platform = MethodChannel('live_activity_channel');
Future<void> _startLiveActivity() async {
try {
await platform.invokeMethod('startLiveActivity');
} on PlatformException catch (e) {
print("Failed to start Live Activity: '${e.message}'.");
}
}
Future<void> _updateLiveActivity(double progress) async {
try {
await platform.invokeMethod('updateLiveActivity', {"progress": progress});
} on PlatformException catch (e) {
print("Failed to update Live Activity: '${e.message}'.");
}
}
Future<void> _endLiveActivity() async {
try {
await platform.invokeMethod('endLiveActivity');
} on PlatformException catch (e) {
print("Failed to end Live Activity: '${e.message}'.");
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Live Activity Test")),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: _startLiveActivity,
child: Text("Start Live Activity"),
),
ElevatedButton(
onPressed: () => _updateLiveActivity(0.5),
child: Text("Update Progress to 50%"),
),
ElevatedButton(
onPressed: _endLiveActivity,
child: Text("End Live Activity"),
),
],
),
);
}
}