skip to Main Content

After upgrading Flutter version I am getting this error in background color

enter image description here

ThemeData(
...
...
...
 
     backgroundColor: Colors.white,

...
...
...);

FOR THE REMAINING PARTS

I was using

  backgroundColor: Theme.of(context).backgroundColor,

–>

I converted to

 backgroundColor:
          Theme.of(context).colorScheme.secondary,

(Because I saw a solution on the internet, old one was giving a mistake)

How can I solve my problem? It seems that problem is about flutter version upgrading. What do you think? Any help will be appreciated.

flutter doctor:

[✓] Flutter (Channel stable, 3.24.3, on macOS 14.4.1  darwin-arm64, locale tr-TR)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0-rc3)
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.3)
[✓] VS Code (version 1.92.1)
[✓] Connected device (4 available)
[✓] Network resources

2

Answers


  1. Use colorScheme.background instead.
    This feature was deprecated after v3.3.0-0.5.pre.

    example

          theme: ThemeData(
            colorScheme: ColorScheme(
              background: Colors.white,
            ),
          ),
    ```
    
    Login or Signup to reply.
  2. Use scaffoldBackgroundColor: Colors.white instead of backgroundColor if you need to change the color of scaffold. If you want to know more about the parameters of ThemeData you can Ctrl+click in windows or Cmd+click on mac on widget you want to know more.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search