Open gustav77 opened 2 years ago
Hey thanks for reporting this. I assume that this behavior doesn't show without the feedback library, right?
@caseycrogers Do you think your recent changes might have introduced this behavior?
yes, of course without the feedback library this behavior doesn't show up.
Am So., 9. Jan. 2022 um 16:37 Uhr schrieb Jonas Uekötter < @.***>:
Hey thanks for reporting this. I assume that this behavior doesn't show without the feedback library, right?
@caseycrogers https://github.com/caseycrogers Do you think your recent changes might have introduced this behavior?
— Reply to this email directly, view it on GitHub https://github.com/ueman/feedback/issues/164#issuecomment-1008320564, or unsubscribe https://github.com/notifications/unsubscribe-auth/AASSYWZCGW5VIMLDYXXPBKDUVGTULANCNFSM5LR3XQLA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you authored the thread.Message ID: @.***>
Tel.: +49 (172) 4026944
Web: https:// http://www.mapletec.de/m http://guckelsberger.wordpress.comapletec.blog
Playing around with this now. There's a decent chance my recent changes introduced this-hard to say without a repro I can test before and after the changes.
@gustav77 can you post a full repro? I cannot get initialize
to print more than once from the following code and opening and closing the keyboard:
import 'package:flutter/material.dart';
void main() {
runApp(BetterFeedback(child: _SecondaryScaffold(isDirty: false)));
}
class _SecondaryScaffold extends StatelessWidget {
_SecondaryScaffold({required this.isDirty}) {
print('\n\ninitialize\n\n');
}
final bool isDirty;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Scaffold 2'),
),
body: const Center(
child: TextField(),
),
);
}
}
I'd like to reproduce what you're describing before fully coming to a conclusion as to whether or not there's a bug with feedback that needs fixing, but in general your app shouldn't rely on widget objects not being re-constructed.
If you want initialization logic for your widget, you have to make it a stateful widget and override initState
. The flutter framework makes no guarantees that a StatelessWidget
object will be long lived and won't be re-constructed. It only guarantees that State<T>
objects are long-lived. If you're putting init logic in the constructor body your app is going to have bugs with or without Better Feedback.
Ah, I see you were referring to the example app: https://github.com/ueman/feedback/blob/06d4c3b835029df0e60934be2d74b522c90e9d22/feedback/example/lib/main.dart#L211
Using this example I can in fact get initialize
to print on keyboard open and close. I'll retest with code from before my changes, but I suspect it'll still be there. The form fields all maintain expected state so there's no malformed behavior in the example code. I think this is a bug specific to your app stemming from using body constructors instead of initState
for initialization logic.
Just confirmed that initialize
prints on keyboard open and close before the scale and expanding sheet changes: https://github.com/ueman/feedback/commit/d7b74f7b627399312acf3a98951b8cca766056b5 .
IMO this is expected behavior not a bug.
This is still happening
@mikewolfd is your issue exactly the same as the reproduction provided above? If so, you cannot (and should not) count on BetterFeedback or any other first or third party flutter widgets only calling widget constructors once. If your app was doing this and working before BetterFeedback then that's just a lucky accident.
Flutter makes no guarantees that a widget object will not be initialized redundantly, it only guarantees that a stateful widget's state object will be initialized once. If you are putting initialization logic in your widget constructors and expecting it to run only once then that is a bug in your code. Try using stateful widgets and initState
instead.
If I've misunderstood your problem, can you provide a repro here?
@ueman I'd recommend closing this issue to make it clear that this is a bug in developers' code and not an issue with BetterFeedback.
Version
2.3.0
Library
feedback
Flutter channel
stable
Flutter version
2.8.1
Platform
iOS
Details
I have an App with lots of forms. Whenever the keyboard appears or disappears, the enclosing widget is recreated.
I love your widget, but I can't use it because of this issue.
Steps to reproduce
You. can reproduce this behaviour with your example. Just change the Text('Hello world') with a Textfield and add a print statement in the constructor:
I can reproduce this behaviour on iOS and web.
Output of
flutter doctor -v