extended_masked_text
extended_masked_text copied to clipboard
Focus MaskedTextController
I wonder if anyone has had this problem.
I have a list of MaskedTextController, however as it is in the middle of the page it throws the focus to it, if I use a TextEditingController this same problem does not happen.
import 'package:extended_masked_text/extended_masked_text.dart';
import 'package:flutter/material.dart';
class NextPage extends StatefulWidget {
@override
_NextPageState createState() => _NextPageState();
}
class _NextPageState extends State<NextPage> {
List<MaskedTextController> list;
@override
void initState() {
list = <MaskedTextController>[];
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: textWidget('Test'),
),
body: SingleChildScrollView(
child: Column(
children: [
ListView.builder(
itemCount: 20,
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemBuilder: (BuildContext context, int index) {
return texte('count $index');
}),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'List Here',
style: TextStyle(fontSize: 26),
),
),
ListView.builder(
itemCount: 10,
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemBuilder: (BuildContext context, int index) {
list.add(MaskedTextController(mask: '*', text: '$index'));
return Column(
children: [
Text('field $index'),
Container(
height: 50,
width: 300,
child: TextField(
controller: list[index],
),
),
],
);
})
],
),
));
}
}
Widget textWidget(String text) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 12.0),
child: Text(text),
);
}
I was taking a look here, note that it is not necessary to load _moveCursor from the beginning, and you can control this with just one more parameter without updateText and one (if) no Future.delayed, if you find it interesting I can do a PR
@lferrerad I test your code above and was not able to reproduce the behavior. I think it is extremely odd that switching the controller would affect the window focus. I even force the controller to update the cursor upon loading the page, and it would not affect the scroll or even the focus.
You could provide the flutter doctor and package version that you are using to run this example? Or even provide the full sample?
Also, I'm intrigued, how exactly you would update the cursor if not in the updateText? I could not understand how it could be done.
Best regards.
@fabricio-godoi https://github.com/lferrerad/maskedtext thank you and have a good week.
@fabricio-godoi https://github.com/lferrerad/maskedtext thank you and have a good week.
Thank you! I will add this fix in the next release.
@lferrerad I've tried to add your fix to the latest version, but had problems with some tests related with the moveCursor: false
inside the constructor.