- Fixed unused field warning in phone_input_screen.dart - Resolved undefined getter 'isoCode' by removing unused code - Fixed undefined class 'User' error by adding proper Firebase import in user_model.dart - Ran dart format to ensure consistent code style across all files - All analyzer issues are now resolved Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
86 lines
2.9 KiB
Dart
86 lines
2.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:intl_phone_field/intl_phone_field.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:phone_login/auth/auth_state.dart';
|
|
|
|
class PhoneInputScreen extends StatefulWidget {
|
|
const PhoneInputScreen({super.key});
|
|
|
|
@override
|
|
State<PhoneInputScreen> createState() => _PhoneInputScreenState();
|
|
}
|
|
|
|
class _PhoneInputScreenState extends State<PhoneInputScreen> {
|
|
final TextEditingController _phoneController = TextEditingController();
|
|
String? _formattedPhone;
|
|
|
|
@override
|
|
void dispose() {
|
|
_phoneController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final authState = Provider.of<AuthState>(context);
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('Enter Phone Number')),
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
IntlPhoneField(
|
|
decoration: const InputDecoration(
|
|
labelText: 'Phone Number',
|
|
border: OutlineInputBorder(borderSide: BorderSide()),
|
|
),
|
|
initialCountryCode: 'US',
|
|
onChanged: (phone) {
|
|
_formattedPhone = phone.completeNumber;
|
|
},
|
|
),
|
|
const SizedBox(height: 20),
|
|
authState.isLoading
|
|
? const Center(child: CircularProgressIndicator())
|
|
: ElevatedButton(
|
|
onPressed: _formattedPhone != null
|
|
? () async {
|
|
if (_formattedPhone != null) {
|
|
await authState.signInWithPhoneNumber(
|
|
_formattedPhone!,
|
|
);
|
|
if (!context.mounted) return;
|
|
|
|
if (authState.errorMessage != null) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(authState.errorMessage!),
|
|
),
|
|
);
|
|
} else {
|
|
context.go('/sms_verify');
|
|
}
|
|
}
|
|
}
|
|
: null,
|
|
child: const Text('Send OTP'),
|
|
),
|
|
if (authState.errorMessage != null)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 16.0),
|
|
child: Text(
|
|
authState.errorMessage!,
|
|
style: const TextStyle(color: Colors.red),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|