New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
textSeparators issue #62
Comments
LateInitializationError: Field '_textSeparators' has already been initialized. When the user goes back to the previous screen and comes back it shows like this. |
I tried it on mobile an same happened |
@eyoeldefare could you please check? |
Can you provide an example of your code so I can see why you're getting this issue? |
import 'package:flutter/material.dart'; void main() { class MyApp extends StatelessWidget { @OverRide
} class MyHomePage extends StatefulWidget { final String title; @OverRide class _MyHomePageState extends State { OutlineInputBorder buildBorder(Color color) { |
I'm using fluter 3.0.3 and textfield_tags 2.0.1 |
Its working for me with your example. I am not sure why you're getting this. Also remove "!" from |
import 'dart:io'; class CreateAccount extends StatefulWidget { class _CreateAccountState extends State { List _accountFormKeys = [ @OverRide @OverRide OutlineInputBorder boxBorder() { OutlineInputBorder buildBorder(Color color) { EdgeInsets padding() { _filePicker() async { buildTopBar() { Widget buildaccountBlock() { Widget buildAddressBlock() { Widget buildDescriptionBlock() { @OverRide _submitForm() async { showErrorMessage(BuildContext context, String msg) { Still I'm having same issue |
I hope bug will solve ASAP, my app not working due to this . |
Any update on this issue? |
Hi, I have the same problem. The Flutter version is 3.0.5 and the package version is 2.0.1. I tested on an Android device. I reproduced the error in simple code: import 'package:flutter/material.dart';
import 'package:textfield_tags/textfield_tags.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const Home(),
);
}
}
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
@override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
late double _distanceToField;
late TextfieldTagsController _controller;
bool isSending = false;
@override
void didChangeDependencies() {
super.didChangeDependencies();
_distanceToField = MediaQuery.of(context).size.width;
}
@override
void dispose() {
super.dispose();
_controller.dispose();
}
@override
void initState() {
super.initState();
_controller = TextfieldTagsController();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "wellcome",
home: Scaffold(
appBar: AppBar(
backgroundColor: const Color.fromARGB(255, 74, 137, 92),
centerTitle: true,
title: const Text('Enter a tag...'),
),
body: isSending
? const Center(child: CircularProgressIndicator())
: Column(children: [
TextFieldTags(
textfieldTagsController: _controller,
initialTags: const [
'pick',
'your',
'favorite',
'programming',
'language'
],
textSeparators: const [' ', ','],
letterCase: LetterCase.normal,
validator: (String tag) {
if (tag == 'php') {
return 'No, please just no';
} else if (_controller.getTags!.contains(tag)) {
return 'you already entered that';
}
return null;
},
inputfieldBuilder:
(context, tec, fn, error, onChanged, onSubmitted) {
return ((context, sc, tags, onTagDelete) {
return Padding(
padding: const EdgeInsets.all(10.0),
child: TextField(
controller: tec,
focusNode: fn,
decoration: InputDecoration(
isDense: true,
border: const OutlineInputBorder(
borderSide: BorderSide(
color: Color.fromARGB(255, 74, 137, 92),
width: 3.0,
),
),
focusedBorder: const OutlineInputBorder(
borderSide: BorderSide(
color: Color.fromARGB(255, 74, 137, 92),
width: 3.0,
),
),
helperText: 'Enter language...',
helperStyle: const TextStyle(
color: Color.fromARGB(255, 74, 137, 92),
),
hintText:
_controller.hasTags ? '' : "Enter tag...",
errorText: error,
prefixIconConstraints: BoxConstraints(
maxWidth: _distanceToField * 0.74),
prefixIcon: tags.isNotEmpty
? SingleChildScrollView(
controller: sc,
scrollDirection: Axis.horizontal,
child: Row(
children: tags.map((String tag) {
return Container(
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(20.0),
),
color: Color.fromARGB(
255, 74, 137, 92),
),
margin: const EdgeInsets.symmetric(
horizontal: 5.0),
padding: const EdgeInsets.symmetric(
horizontal: 10.0, vertical: 5.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
InkWell(
child: Text(
'#$tag',
style: const TextStyle(
color: Colors.white),
),
onTap: () {
print("$tag selected");
},
),
const SizedBox(width: 4.0),
InkWell(
child: const Icon(
Icons.cancel,
size: 14.0,
color: Color.fromARGB(
255, 233, 233, 233),
),
onTap: () {
onTagDelete(tag);
},
)
],
),
);
}).toList()),
)
: null,
),
onChanged: onChanged,
onSubmitted: onSubmitted,
),
);
});
},
),
ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(
const Color.fromARGB(255, 74, 137, 92),
),
),
onPressed: () async {
setState(() {
isSending = true;
});
// simulate validations
await Future.delayed(const Duration(seconds: 3));
// simulate failed validations and display text field tags again
setState(() {
isSending = false;
});
},
child: const Text('SEND'),
),
])),
);
}
} The error messages:
|
The error occurs when I have to re-display TextFieldTags |
textfield_tags/lib/src/controller.dart Lines 26 to 30 in 8a8c889
Removing the |
After solving the current issue, another issue occurs:
|
The following change seems to resolve this issue. textfield_tags/lib/src/main.dart Lines 69 to 74 in 8a8c889
Update the code above: _ttc.addListener(() {
if (mounted) {
setState(() {
_error = _ttc.getError;
_tags = _ttc.getTags;
});
}
}); |
|
There is a PR to solve this issue, I will merge when I have free time. |
I hope it will merge ASAP |
Thank you for awesome package. |
I tinkered with the code locally and have found that the issue is due to the controller being initialised on the widget's initState. This is especially troublesome if you want to keep the controller in a state outside the widget itself. Essentially, if you have a ListView or PageView that disposes the widget, but keeping the controller alive somewhere else such as in a statement management solution (in my case GetxController). Took me a few tries, but the below code has now solved my problem: main.dart
controller.dart
|
LateInitializationError: Field '_textSeparators@1298091221' has already been initialized.
I tried in many ways but still I could not solve it
can you please help me regarding it.
The text was updated successfully, but these errors were encountered: