aboutsummaryrefslogtreecommitdiffstats
path: root/lib/main.dart
diff options
context:
space:
mode:
authorMalik Talha <talhamalik727x@gmail.com>2023-10-23 02:00:01 +0500
committerMalik Talha <talhamalik727x@gmail.com>2023-10-26 21:36:57 +0500
commit8417e9daeecbdb3847de401b0fcc6304d246a787 (patch)
treea9dafba232ee7e458358861d1356636c079a12da /lib/main.dart
parent8d38450e46ff3854ade4005c4132edfb1aabb9b4 (diff)
Add flutter voice assistant app
A flutter based gRPC client Voice Assistant made specifically to communicate with the Voice Agent service. SPEC-4906 Signed-off-by: Malik Talha <talhamalik727x@gmail.com> Change-Id: Ic4a382c1cdb78f1a79f985e3d37ce2fb06c53203
Diffstat (limited to 'lib/main.dart')
-rw-r--r--lib/main.dart77
1 files changed, 77 insertions, 0 deletions
diff --git a/lib/main.dart b/lib/main.dart
new file mode 100644
index 0000000..bc5b84b
--- /dev/null
+++ b/lib/main.dart
@@ -0,0 +1,77 @@
+import 'package:flutter/material.dart';
+import 'package:provider/provider.dart';
+import 'models/app_state.dart';
+import 'screens/home_screen.dart';
+import 'screens/error_screen.dart';
+import 'providers/service_status.dart';
+import 'grpc/generated/voice_agent.pbgrpc.dart';
+import 'grpc/voice_agent_client.dart';
+import 'utils/app_config.dart';
+
+void main() async {
+ WidgetsFlutterBinding.ensureInitialized();
+
+ final serviceStatusProvider = ServiceStatusProvider();
+
+ // get config variables
+ final config = await AppConfig.loadFromAsset();
+
+ // Check the service status initially
+ final initialServiceStatus = await checkServiceStatus(config);
+ serviceStatusProvider.setServiceStatus(initialServiceStatus.status);
+
+ runApp(
+ MultiProvider(
+ providers: [
+ ChangeNotifierProvider(create: (_) => AppState()),
+ ChangeNotifierProvider.value(value: serviceStatusProvider),
+ ],
+ child: App(
+ config: config,
+ onRetry: () async {
+ final serviceStatus = await checkServiceStatus(
+ config); // Retry connecting to the server
+
+ if (serviceStatus.status) {
+ serviceStatusProvider
+ .setServiceStatus(true); // Update the service status
+ }
+ },
+ ),
+ ),
+ );
+}
+
+Future<ServiceStatus> checkServiceStatus(AppConfig config) async {
+ final client = VoiceAgentClient(config.grpcHost, config.grpcPort);
+ final serviceStatus = await client.checkServiceStatus();
+ client.shutdown();
+ return serviceStatus;
+}
+
+class App extends StatelessWidget {
+ final AppConfig config;
+ final VoidCallback onRetry;
+
+ const App({Key? key, required this.config, required this.onRetry});
+
+ @override
+ Widget build(BuildContext context) {
+ return MaterialApp(
+ title: 'AGL Voice Assistant',
+ theme: ThemeData(
+ useMaterial3: true,
+ colorScheme: ColorScheme.fromSeed(seedColor: Colors.green),
+ ),
+ home: Consumer<ServiceStatusProvider>(
+ builder: (context, provider, child) {
+ return provider.isServiceOnline
+ ? HomePage(config: config)
+ : ErrorScreen(
+ onRetry: onRetry, // Pass the callback to the ErrorScreen
+ ); // Conditionally render HomePage or ErrorScreen
+ },
+ ),
+ );
+ }
+}