| 1 | import 'package:flutter/material.dart'; |
| 2 | import 'package:flutter/services.dart'; |
| 3 | import 'package:flutter_secure_storage/flutter_secure_storage.dart'; |
| 4 | import 'package:go_router/go_router.dart'; |
| 5 | import 'package:aero/constants/main.dart'; |
| 6 | |
| 7 | class WearablesLoginScreen extends StatefulWidget |
| 8 | final String wearableName; |
| 9 | const WearablesLoginScreen({ |
| 10 | super.key, |
| 11 | required this.wearableName, |
| 12 | }); |
| 13 | |
| 14 | @override |
| 15 | State<WearablesLoginScreen> createState |
| 16 | } |
| 17 | |
| 18 | class _WearablesLoginScreenState extends State |
| 19 | @override |
| 20 | Widget build(BuildContext |
| 21 | return Scaffold( |
| 22 | appBar: AppBar( |
| 23 | leading: IconButton( |
| 24 | onPressed: () { |
| 25 | context.go("/"); |
| 26 | }, |
| 27 | icon: Icon( |
| 28 | Icons.arrow_back, |
| 29 | ), |
| 30 | ), |
| 31 | title: Text( |
| 32 | "Login Request", |
| 33 | ), |
| 34 | ), |
| 35 | body: SafeArea( |
| 36 | child: Center( |
| 37 | child: Column( |
| 38 | mainAxisAlignment: MainAxisAlignment.center, |
| 39 | children: [ |
| 40 | Padding( |
| 41 | padding: EdgeInsets.all( |
| 42 | child: Text( |
| 43 | "Would you like to sign in to your watch (${widget.wearableName} |
| 44 | textAlign: TextAlign.center, |
| 45 | style: Theme.of(context) |
| 46 | ), |
| 47 | ), |
| 48 | ElevatedButton( |
| 49 | onPressed: () async { |
| 50 | final storage = const |
| 51 | final token = await storage. |
| 52 | key: AUTH_TOKEN_KEY, |
| 53 | ); |
| 54 | if (token == null || (token. |
| 55 | if (context.mounted) { |
| 56 | showDialog( |
| 57 | context: context, |
| 58 | builder: (BuildContext context) { |
| 59 | return AlertDialog( |
| 60 | title: Text("Login Required"), |
| 61 | content: Text( |
| 62 | "Please login in the app first before connecting your watch."), |
| 63 | actions: [ |
| 64 | TextButton( |
| 65 | onPressed: () { |
| 66 | Navigator.pop(context); |
| 67 | }, |
| 68 | child: Text("Cancel"), |
| 69 | ), |
| 70 | ElevatedButton( |
| 71 | onPressed: () { |
| 72 | Navigator.pop(context); |
| 73 | context.go("/auth/login"); |
| 74 | }, |
| 75 | child: Text("Login"), |
| 76 | ), |
| 77 | ], |
| 78 | ); |
| 79 | }, |
| 80 | ); |
| 81 | } |
| 82 | } else { |
| 83 | final channel = MethodChannel( |
| 84 | channel.invokeMethod( |
| 85 | "loginInWearable", |
| 86 | token, |
| 87 | ); |
| 88 | } |
| 89 | }, |
| 90 | child: Text( |
| 91 | "Sign In", |
| 92 | ), |
| 93 | ), |
| 94 | ], |
| 95 | ), |
| 96 | ), |
| 97 | ), |
| 98 | ); |
| 99 | } |
| 100 | } |