feat: add sounds
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:pinput/pinput.dart';
|
||||
|
||||
import '../../../../core/theme/app_theme.dart';
|
||||
import '../../../../core/widgets/game_ui.dart';
|
||||
@@ -10,7 +10,7 @@ import '../bloc/auth_event.dart';
|
||||
import '../bloc/auth_state.dart';
|
||||
import '../bloc/otp_status.dart';
|
||||
|
||||
/// صفحهی ورود کد یکبارمصرف (۵ رقمی).
|
||||
/// صفحهی ورود کد یکبارمصرف (۵ رقمی) با pinput و تکمیل خودکارِ پیامک.
|
||||
class OtpScreen extends StatefulWidget {
|
||||
const OtpScreen({super.key});
|
||||
|
||||
@@ -29,8 +29,26 @@ class _OtpScreenState extends State<OtpScreen> {
|
||||
|
||||
bool get _valid => _controller.text.trim().length == 5;
|
||||
|
||||
void _submit(BuildContext context) {
|
||||
if (_valid) {
|
||||
context.read<AuthBloc>().add(CheckOtpEvent(_controller.text.trim()));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final defaultPin = PinTheme(
|
||||
width: 52,
|
||||
height: 60,
|
||||
textStyle: const TextStyle(
|
||||
color: Colors.white, fontSize: 24, fontWeight: FontWeight.bold),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.bgDark,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: AppColors.goldDark, width: 1.5),
|
||||
),
|
||||
);
|
||||
|
||||
return Scaffold(
|
||||
body: GameBackground(
|
||||
child: BlocConsumer<AuthBloc, AuthState>(
|
||||
@@ -62,31 +80,39 @@ class _OtpScreenState extends State<OtpScreen> {
|
||||
Text('کد پیامکشده به ${state.mobile} را وارد کنید',
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(color: Colors.white70)),
|
||||
const SizedBox(height: 20),
|
||||
TextField(
|
||||
controller: _controller,
|
||||
keyboardType: TextInputType.number,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontSize: 28, letterSpacing: 12),
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.digitsOnly,
|
||||
LengthLimitingTextInputFormatter(5),
|
||||
],
|
||||
decoration:
|
||||
const InputDecoration(hintText: '- - - - -'),
|
||||
onChanged: (_) => setState(() {}),
|
||||
const SizedBox(height: 22),
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Pinput(
|
||||
length: 5,
|
||||
controller: _controller,
|
||||
autofocus: true,
|
||||
keyboardType: TextInputType.number,
|
||||
closeKeyboardWhenCompleted: true,
|
||||
defaultPinTheme: defaultPin,
|
||||
focusedPinTheme: defaultPin.copyWith(
|
||||
decoration: defaultPin.decoration!.copyWith(
|
||||
border:
|
||||
Border.all(color: AppColors.gold, width: 2),
|
||||
),
|
||||
),
|
||||
separatorBuilder: (_) => const SizedBox(width: 8),
|
||||
pinAnimationType: PinAnimationType.fade,
|
||||
// تکمیل خودکارِ کد از پیامک (Android: SMS User Consent).
|
||||
androidSmsAutofillMethod:
|
||||
AndroidSmsAutofillMethod.smsUserConsentApi,
|
||||
onChanged: (_) => setState(() {}),
|
||||
onCompleted: (_) => _submit(context),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const SizedBox(height: 22),
|
||||
GameButton(
|
||||
label: 'ورود',
|
||||
width: double.infinity,
|
||||
colors: const [Color(0xFF3FA34D), Color(0xFF1B5E20)],
|
||||
onTap: (!_valid || loading)
|
||||
? null
|
||||
: () => context
|
||||
.read<AuthBloc>()
|
||||
.add(CheckOtpEvent(_controller.text.trim())),
|
||||
: () => _submit(context),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: loading ? null : () => context.pop(),
|
||||
|
||||
Reference in New Issue
Block a user