Skip to content
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

DropdownButtonFormField is not re-rendered after value is changed programmatically #56898

Closed
lazarvgd opened this issue May 11, 2020 · 24 comments · Fixed by #57037
Closed

DropdownButtonFormField is not re-rendered after value is changed programmatically #56898

lazarvgd opened this issue May 11, 2020 · 24 comments · Fixed by #57037
Labels
c: regression It was better in the past than it is now f: material design flutter/packages/flutter/material repository. found in release: 1.17 Found to occur in 1.17 found in release: 1.18 Occurs in 1.18 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on

Comments

@lazarvgd
Copy link

lazarvgd commented May 11, 2020

I just created a simple app in order to see what am I doing wrong

The code:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;
  List<int> myList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
  int currentNumber = 1;
  int anotherNumber = 9;

  void _incrementCounter() {
    setState(() {
      _counter++;
      anotherNumber = _counter;
      currentNumber = _counter;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
            DropdownButtonFormField<int>(
              value: currentNumber,
              items: myList.map((int value) {
                return DropdownMenuItem<int>(
                  value: value,
                  child: Container(
                    width: 200,
                    child: Text(
                      value.toString(),
                    ),
                  ),
                );
              }).toList(),
              onChanged: (int newValue) {
                setState(() {
                  anotherNumber = newValue;
                  currentNumber = newValue;
                });
              },
            ),
            DropdownButtonFormField<int>(
              value: anotherNumber,
              items: myList.map((int value) {
                return DropdownMenuItem<int>(
                  value: value,
                  child: Container(
                    width: 200,
                    child: Text(
                      value.toString(),
                    ),
                  ),
                );
              }).toList(),
              onChanged: (int newValue) {
                setState(() {
                  anotherNumber = newValue;
                });
              },
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}

The flutter doctor -v:

$ flutter doctor -v
[✓] Flutter (Channel stable, v1.17.0, on Mac OS X 10.15.4 19E287, locale en-RS)
    • Flutter version 1.17.0 at /Users/lazarjovicic/flutter
    • Framework revision e6b34c2b5c (9 days ago), 2020-05-02 11:39:18 -0700
    • Engine revision 540786dd51
    • Dart version 2.8.1

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/lazarjovicic/Library/Android/sdk
    • Platform android-29, build-tools 29.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.4.1, Build version 11E503a
    • CocoaPods version 1.8.4

[✓] Android Studio (version 3.6)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 45.1.1
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[✓] VS Code (version 1.44.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.10.1

[✓] Connected device (1 available)
    • SM G970F • RF8M728WTMP • android-arm64 • Android 10 (API 29)

• No issues found!

The demonstration with code above:
https://streamable.com/fwwd46
EDIT:
The Expectation:
Update the first dropdown filed -> the second dropdown field will be updated automatically

The Result:
Update the first dropdown field -> the second dropdown field remains unchanged.

Please let me know if you need additional information or any further explanation regarding the problem.

Thanks

@lazarvgd
Copy link
Author

I check version 1.13.4 and this actually works

$ flutter doctor -v
[✓] Flutter (Channel unknown, v1.13.4, on Mac OS X 10.15.4 19E287, locale en-RS)
• Flutter version 1.13.4 at /Users/lazarjovicic/flutter
• Framework revision bd25f70 (5 months ago), 2019-12-19 09:45:02 -0800
• Engine revision 0f90e65
• Dart version 2.8.0 (build 2.8.0-dev.0.0 aa6709974d)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/lazarjovicic/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.4.1, Build version 11E503a
• CocoaPods version 1.8.4

[✓] Android Studio (version 3.6)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 45.1.1
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[✓] VS Code (version 1.44.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.10.1

[✓] Connected device (2 available)
• SM G970F • RF8M728WTMP • android-arm64 • Android 10 (API 29)
• iPhone 6 • B56B92F3-A2D9-4F91-A161-E2761F80C51C • ios • com.apple.CoreSimulator.SimRuntime.iOS-12-4 (simulator)

• No issues found!

@lazarvgd lazarvgd changed the title Flutter setState does not work correctly with version 1.17 Flutter setState does not work correctly with version 1.17.0 May 11, 2020
@VladyslavBondarenko
Copy link

Reproduces with current dev 1.19.0-0.0.pre as well.
But yes, 1.13.4 is working as intended

@VladyslavBondarenko VladyslavBondarenko added found in release: 1.17 Found to occur in 1.17 found in release: 1.18 Occurs in 1.18 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on c: regression It was better in the past than it is now labels May 11, 2020
@VladyslavBondarenko VladyslavBondarenko changed the title Flutter setState does not work correctly with version 1.17.0 DropdownButtonFormField is not re-rendered after value is changed programmatically May 11, 2020
@VladyslavBondarenko
Copy link

I changed the title, because new values are set by setState, but second DropdownButtonFormField is not updated

  @override
  Widget build(BuildContext context) {

    print(currentNumber);
    print(anotherNumber);

    return Scaffold(

@pedromassango
Copy link
Member

DropdownButtonFormField widget is really using badly the value param. I just found a related issue here #56929

You can reproduce it by tapping FAB button 10 times using the example code in this issue!

@HansMuller
Copy link
Contributor

CC @shihaohong

@jlubeck
Copy link
Contributor

jlubeck commented May 12, 2020

I can confirm @pedromassango PR fixes my issue: #57006
Pretty sure it fixes this one as well

@pedromassango
Copy link
Member

Thanks. I'm just adding tests, before opening the PR for review

@pedromassango
Copy link
Member

PR moved to #56898

@shihaohong
Copy link
Contributor

shihaohong commented May 13, 2020

I've marked this issue as a candidate for cherry-picking into the stable branch since this is a regression that has resulted in multiple open issues over the last few days (#57006, #56983, #57066) and revived an older DropdownButtonFormField issue (#27821 (comment)), presumably from devs trying to find an answer to their problem.

See https://github.com/flutter/flutter/wiki/Flutter-Cherrypick-Process for more information on how the process works.

@pedromassango
Copy link
Member

@shihaohong Can you confirm that this is not a regretion too: #56365? Or it always behave that way?!

@shihaohong
Copy link
Contributor

@pedromassango I don't know since I haven't looked at that issue yet. However, since that issue is unrelated to this one, let's discuss that one in #56365 and not here.

@jlubeck
Copy link
Contributor

jlubeck commented May 14, 2020

Maybe include the cp: 1.18 label as well??

@lazarvgd
Copy link
Author

When we can expect this issue to be solved?
Thanks

@pedromassango
Copy link
Member

This was already solved. We're just waiting to have it in the next Flutter beta release!

@lazarvgd
Copy link
Author

This was already solved. We're just waiting to have it in the next Flutter beta release!

Sorry, I wasn't clear, when we can expect this issue to be in stable release?

thanks

@pedromassango
Copy link
Member

Ok. Can take time for stable channel to be released. So if you really want this, you may want to use the beta channel, once this lands to beta

@lazarvgd
Copy link
Author

Ok. Can take time for stable channel to be released. So if you really want this, you may want to use the beta channel, once this lands to beta

Thanks, but that is a bad idea for production app... thanks

@pedromassango
Copy link
Member

Please note that I never know when a stable version will be released. I just say that because this PR is not even in a beta release, so it can take time to go to stable.

@pcsosinski
Copy link

@shihaohong which commit(s) are needed for the 1.17 branch if we cherrypick this?

@shihaohong
Copy link
Contributor

@pcsosinski This is the commit needed for the cherrypick: 1aaf73f

@tvolkert
Copy link
Contributor

eng approval for cp of #57037 into 1.17

@pedromassango
Copy link
Member

@lazarvgd This has landed to 1.17.2

@pcsosinski
Copy link

removed 1.18 label as we're going to 1.19 for beta soon.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
c: regression It was better in the past than it is now f: material design flutter/packages/flutter/material repository. found in release: 1.17 Found to occur in 1.17 found in release: 1.18 Occurs in 1.18 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on
Projects
None yet
8 participants