fix: otp component
This commit is contained in:
parent
4b4b42beae
commit
7ec266cded
|
@ -1,4 +1,3 @@
|
||||||
import 'package:cims_apps/application/component/button/button_view.dart';
|
|
||||||
import 'package:cims_apps/application/component/otp/otp_viewmodel.dart';
|
import 'package:cims_apps/application/component/otp/otp_viewmodel.dart';
|
||||||
import 'package:cims_apps/application/component/text_caption/text_caption.dart';
|
import 'package:cims_apps/application/component/text_caption/text_caption.dart';
|
||||||
import 'package:cims_apps/application/theme/color_palette.dart';
|
import 'package:cims_apps/application/theme/color_palette.dart';
|
||||||
|
@ -61,12 +60,25 @@ class OtpView extends StatelessWidget {
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
onCompleted: (pin) => provider.enableButton(),
|
||||||
|
onChanged: (value) {
|
||||||
|
if (provider.ctrlPin.length != 4) {
|
||||||
|
provider.enableButton(isActive: false);
|
||||||
|
}
|
||||||
|
},
|
||||||
),
|
),
|
||||||
ButtonView(
|
Container(
|
||||||
name: 'Verify',
|
margin: const EdgeInsets.symmetric(vertical: 32.0),
|
||||||
// disabled: !provider.buttonIsActive,
|
width: SizeConfig.width,
|
||||||
// backgroundColor: ColorPalette.grey,
|
height: SizeConfig.height * .07,
|
||||||
onPressed: () {
|
child: ElevatedButton(
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
elevation: 0,
|
||||||
|
backgroundColor: ColorPalette.primary,
|
||||||
|
),
|
||||||
|
onPressed: !provider.buttonIsActive
|
||||||
|
? null
|
||||||
|
: () {
|
||||||
if (provider.formKey.currentState!.validate()) {
|
if (provider.formKey.currentState!.validate()) {
|
||||||
final pin = provider.ctrlPin.text;
|
final pin = provider.ctrlPin.text;
|
||||||
provider.validateOtp(pin).then((value) {
|
provider.validateOtp(pin).then((value) {
|
||||||
|
@ -80,6 +92,15 @@ class OtpView extends StatelessWidget {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
child: const Text(
|
||||||
|
'Verify',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
));
|
));
|
||||||
|
@ -106,7 +127,9 @@ class OtpView extends StatelessWidget {
|
||||||
),
|
),
|
||||||
_otpContent(context, provider),
|
_otpContent(context, provider),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {},
|
onPressed: () {
|
||||||
|
provider.ctrlPin.clear();
|
||||||
|
},
|
||||||
child: const Text(
|
child: const Text(
|
||||||
'Resend Code',
|
'Resend Code',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
|
|
|
@ -14,4 +14,9 @@ class OtpViewModel extends ChangeNotifier {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void enableButton({bool isActive = true}) {
|
||||||
|
buttonIsActive = isActive;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user