-
Notifications
You must be signed in to change notification settings - Fork 15
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
TextFields are getting rebuild even when I use GlobalKeys. #12
Comments
upd: Also, defining global key outside view function does not work either. dynamic view() {
var key = GlobalKey();
return (c,d,m) => TextField(key: key)
}
Program(
view: view(),
init: () => Upd(null),
update: (msg, m) => Upd(null),
); |
@cab404 Hi. Have you tried it in pure Flutter, without Dartea? It doesn't look like it's library's issue. |
Yes, I did, it works OK.
On July 23, 2019 11:20:32 PM GMT+03:00, Pavel Shilyagov ***@***.***> wrote:
@cab404 Hi. Have you tried it in pure Flutter, without Dartea? It
doesn't look like it's library's issue.
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#12 (comment)
—
cab
|
Sorry, I did not include enough context (thought that I pinned down the issue). Here's an example. void main() => runApp(MaterialApp(
routes: {
"/": (c) => Scaffold(
backgroundColor: Colors.amber,
body: DarteaMessagesBus(
child: ProgramWidget(
withMessagesBus: true,
init: () => Upd(1),
view: (c, d, m) => Center(
child: TextField(
key: GlobalKey(),
),
),
update: (m, s) => Upd(1)),
),
)
},
initialRoute: "/",
)); You can remove GlobalKey(), and it would work fine, but otherwise it will close the keyboard every time text field is focused. Sorry again for initial lack of the details :( |
Sorry for the delay. I will try to reproduce and investigate this issue. Hope I can do it till next week. |
Hi @cab404 . I've reproduced this issues, and it's valid Flutter behavior. It isn't related to Dartea. You have to define GlobalKey outside the View function, because it can be called anytime framework decides to. Focusing triggers rebuilding the tree and calling View function, and GlobalKey creates each time. You can create that key in file level, or just pass it to the main View function of the Program. |
@p69 The problem is that if I use GlobalKey at file level, then there's no way to create items with it, and I see no other way to get state of a text field on button press. How should I write this? import 'package:flutter/material.dart';
import 'package:dartea/dartea.dart';
var k = GlobalKey<FormFieldState<String>>();
getItem() => ProgramWidget(
withMessagesBus: true,
init: () => Upd(1),
view: () {
return (c, d, m) {
return Column(
children: <Widget>[
Center(
child: TextField(
key: k,
),
),
FlatButton(
onPressed: () => print(k.currentState.value),
child: Text("Submit"))
],
);
};
}(),
update: (m, s) => Upd(1),
);
void main() => runApp(MaterialApp(
routes: {
"/": (c) {
return Scaffold(
backgroundColor: Colors.amber,
body: ListView.builder(itemBuilder: (c, i) => getItem()),
);
}
},
initialRoute: "/",
));
|
@cab404 You can use TextEditController for getting and setting text in TextField. |
@p69 ty, that helped :з |
To reproduce:
Each time you try to focus TextField it rebuilds and thus unfocuses. Without GlobalKey specified that is not a problem.
The text was updated successfully, but these errors were encountered: