How Pinput states and PinTheme work
masterThe Pinput widget transitions between 6 states: default, focused, submitted, following, disabled, and error. You can customize the appearance of each state using the PinTheme class and passing specific theme parameters to the Pinput widget.
PinTheme Properties
| Property | Type | Default |
|---|---|---|
width | double | 56.0 |
height | double | 60.0 |
textStyle | TextStyle | TextStyle() |
margin | EdgeInsetsGeometry | - |
padding | EdgeInsetsGeometry | - |
constraints | BoxConstraints | - |
To avoid repeating code, you can create a defaultPinTheme and use copyDecorationWith or copyWith to derive other state themes (like focusedPinTheme or submittedPinTheme).
final defaultPinTheme = PinTheme(
width: 56,
height: 56,
textStyle: TextStyle(fontSize: 20, color: Color.fromRGBO(30, 60, 87, 1), fontWeight: FontWeight.w600),
decoration: BoxDecoration(
border: Border.all(color: Color.fromRGBO(234, 239, 243, 1)),
borderRadius: BorderRadius.circular(20),
),
);
final focusedPinTheme = defaultPinTheme.copyDecorationWith(
border: Border.all(color: Color.fromRGBO(114, 178, 238, 1)),
borderRadius: BorderRadius.circular(8),
);
final submittedPinTheme = defaultPinTheme.copyWith(
decoration: defaultPinTheme.decoration.copyWith(
color: Color.fromRGBO(234, 239, 243, 1),
),
);
return Pinput(
defaultPinTheme: defaultPinTheme,
focusedPinTheme: focusedPinTheme,
submittedPinTheme: submittedPinTheme,
onCompleted: (pin) => print(pin),
);