Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #46 from SergeShkurko/master
Browse files Browse the repository at this point in the history
Fixed cursor in cupertino, fixed #39, fixed textarea for paste code
  • Loading branch information
LiewJunTung authored May 26, 2020
2 parents 27cf747 + 7daecb1 commit 2769cf1
Showing 1 changed file with 56 additions and 52 deletions.
108 changes: 56 additions & 52 deletions lib/pin_code_text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,6 @@ class PinCodeTextFieldState extends State<PinCodeTextField>
}
}

bool _isNumeric(String s) {
if (s == null) {
return false;
}
var n = int.tryParse(s);
return n != null && n > -1;
}

void _initTextController() {
if (widget.controller == null) {
Expand All @@ -305,6 +298,23 @@ class PinCodeTextFieldState extends State<PinCodeTextField>
}
}

double get _width {
var width = 0.0;
for (var i = 0; i < widget.maxLength; i++) {
width += widget.pinBoxWidth;
if (i == 0) {
width += widget.pinBoxOuterPadding?.left ?? 0;
} else if (i + 1 == widget.maxLength) {
width += widget.pinBoxOuterPadding?.right ?? 0;
} else {
width += widget.pinBoxOuterPadding?.left ??
0 + widget.pinBoxOuterPadding?.right ??
0;
}
}
return width;
}

@override
void dispose() {
if (widget.focusNode == null) {
Expand All @@ -322,8 +332,7 @@ class PinCodeTextFieldState extends State<PinCodeTextField>

@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
return Stack(
children: <Widget>[
_touchPinBoxRow(),
!widget.isCupertino ? _fakeTextInput() : _fakeTextInputCupertino(),
Expand Down Expand Up @@ -355,54 +364,49 @@ class PinCodeTextFieldState extends State<PinCodeTextField>
width: 0.0,
),
);
return Stack(
children: <Widget>[
Container(
width: 0.1,
height: 16.0, // RenderBoxDecorator subtextGap constant is 8.0
child: TextField(
autofocus: !kIsWeb ? widget.autofocus : false,
focusNode: focusNode,
controller: widget.controller,
keyboardType: widget.keyboardType,
inputFormatters: widget.keyboardType == TextInputType.number
? <TextInputFormatter>[
WhitelistingTextInputFormatter.digitsOnly
]
: null,
style: TextStyle(
height: 0.1, color: Colors.transparent,
return Container(
width: _width,
height: widget.pinBoxHeight,
child: TextField(
autofocus: !kIsWeb ? widget.autofocus : false,
focusNode: focusNode,
controller: widget.controller,
keyboardType: widget.keyboardType,
inputFormatters: widget.keyboardType == TextInputType.number
? <TextInputFormatter>[WhitelistingTextInputFormatter.digitsOnly]
: null,
style: TextStyle(
height: 0.1, color: Colors.transparent,
// color: Colors.transparent,
),
decoration: InputDecoration(
focusedErrorBorder: transparentBorder,
errorBorder: transparentBorder,
disabledBorder: transparentBorder,
enabledBorder: transparentBorder,
focusedBorder: transparentBorder,
counterText: null,
counterStyle: null,
helperStyle: TextStyle(
height: 0.0,
color: Colors.transparent,
),
labelStyle: TextStyle(height: 0.1),
fillColor: Colors.transparent,
border: InputBorder.none,
),
cursorColor: Colors.transparent,
maxLength: widget.maxLength,
onChanged: _onTextChanged,
),
decoration: InputDecoration(
focusedErrorBorder: transparentBorder,
errorBorder: transparentBorder,
disabledBorder: transparentBorder,
enabledBorder: transparentBorder,
focusedBorder: transparentBorder,
counterText: null,
counterStyle: null,
helperStyle: TextStyle(
height: 0.0,
color: Colors.transparent,
),
labelStyle: TextStyle(height: 0.1),
fillColor: Colors.transparent,
border: InputBorder.none,
),
],
cursorColor: Colors.transparent,
showCursor: false,
maxLength: widget.maxLength,
onChanged: _onTextChanged,
),
);
}

Widget _fakeTextInputCupertino() {
return Container(
width: 0.1,
height: 0.1,
width: _width,
height: widget.pinBoxHeight,
child: CupertinoTextField(
autofocus: !kIsWeb ? widget.autofocus : false,
focusNode: focusNode,
Expand All @@ -419,6 +423,7 @@ class PinCodeTextFieldState extends State<PinCodeTextField>
border: null,
),
cursorColor: Colors.transparent,
showCursor: false,
maxLength: widget.maxLength,
onChanged: _onTextChanged,
),
Expand All @@ -434,9 +439,8 @@ class PinCodeTextFieldState extends State<PinCodeTextField>
if (text.length < currentIndex) {
strList[text.length] = "";
} else {
for (int i = currentIndex; i < text.length; i ++) {
strList[i] =
widget.hideCharacter ? widget.maskCharacter : text[i];
for (int i = currentIndex; i < text.length; i++) {
strList[i] = widget.hideCharacter ? widget.maskCharacter : text[i];
}
}
currentIndex = text.length;
Expand Down

0 comments on commit 2769cf1

Please sign in to comment.