mirror of
https://github.com/Iconica-Development/flutter_login_widget.git
synced 2025-05-19 13:43:44 +02:00
80 lines
2.4 KiB
Dart
80 lines
2.4 KiB
Dart
|
import 'package:flutter/material.dart';
|
||
|
import 'package:pinput/pinput.dart';
|
||
|
|
||
|
class MFAWidget extends StatefulWidget {
|
||
|
const MFAWidget(
|
||
|
{required this.onCompleted,
|
||
|
this.onSubmitted,
|
||
|
this.defaultPinTheme,
|
||
|
this.focusedPinTheme,
|
||
|
this.submittedPinTheme,
|
||
|
this.followingPinTheme,
|
||
|
this.disabledPinTheme,
|
||
|
this.errorPinTheme,
|
||
|
this.seperatorPositions,
|
||
|
this.errorBuilder,
|
||
|
this.errorText,
|
||
|
this.errorTextStyle,
|
||
|
this.validator,
|
||
|
this.submitButtonBuilder,
|
||
|
super.key})
|
||
|
: assert(
|
||
|
onSubmitted != null && submitButtonBuilder != null,
|
||
|
);
|
||
|
|
||
|
final Function(String code) onCompleted;
|
||
|
final Function(String code)? onSubmitted;
|
||
|
final PinTheme? defaultPinTheme;
|
||
|
final PinTheme? focusedPinTheme;
|
||
|
final PinTheme? submittedPinTheme;
|
||
|
final PinTheme? followingPinTheme;
|
||
|
final PinTheme? disabledPinTheme;
|
||
|
final PinTheme? errorPinTheme;
|
||
|
final List<int>? seperatorPositions;
|
||
|
final String? errorText;
|
||
|
final String? Function(String?)? validator;
|
||
|
final Widget Function(String?, String)? errorBuilder;
|
||
|
final TextStyle? errorTextStyle;
|
||
|
final Widget Function(Function onTap)? submitButtonBuilder;
|
||
|
|
||
|
@override
|
||
|
State<MFAWidget> createState() => _MFAWidgetState();
|
||
|
}
|
||
|
|
||
|
class _MFAWidgetState extends State<MFAWidget> {
|
||
|
final TextEditingController _controller = TextEditingController();
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Column(
|
||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||
|
children: [
|
||
|
Pinput(
|
||
|
defaultPinTheme: widget.defaultPinTheme,
|
||
|
focusedPinTheme: widget.focusedPinTheme,
|
||
|
submittedPinTheme: widget.submittedPinTheme,
|
||
|
followingPinTheme: widget.followingPinTheme,
|
||
|
disabledPinTheme: widget.disabledPinTheme,
|
||
|
errorPinTheme: widget.errorPinTheme,
|
||
|
separatorPositions: widget.seperatorPositions,
|
||
|
errorBuilder: widget.errorBuilder,
|
||
|
errorText: widget.errorText,
|
||
|
errorTextStyle: widget.errorTextStyle,
|
||
|
validator: widget.validator,
|
||
|
controller: _controller,
|
||
|
length: 6,
|
||
|
onCompleted: (_) {
|
||
|
widget.onCompleted(_controller.text);
|
||
|
},
|
||
|
),
|
||
|
if (widget.onSubmitted != null &&
|
||
|
widget.submitButtonBuilder != null) ...[
|
||
|
widget.submitButtonBuilder!(() {
|
||
|
widget.onSubmitted!(_controller.text);
|
||
|
}),
|
||
|
],
|
||
|
],
|
||
|
);
|
||
|
}
|
||
|
}
|