Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the new method for the deprecated backgroundColor

Tags:

flutter

dart

I was following an old flutter tutorial in which backgroundColor was used. Here is what I wrote following the tutorial:

Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'My app',
      theme: ThemeData.dark().copyWith(
        backgroundColor: backgroundColor,
      ),
      home: const Text("My UI page"),
    );
  }
}

The myBackgroundColor is a const in another file consiting all the colors for the app. What should I write in theme to apply myBackgroundColor?

The flutter docs say backgroundColor is deprecated and use colorScheme.background instead. But when using colorScheme.background I get an error sayind undefined name 'colorScheme'.

like image 559
Rohan_7761 Avatar asked Oct 11 '25 23:10

Rohan_7761


1 Answers

As it states

'backgroundColor' is deprecated and shouldn't be used. Use colorScheme.background instead.

Try

theme: ThemeData.from(
  colorScheme: const ColorScheme.dark(
    background: Colors.black,
  ),
),

Update:

'background' is deprecated and shouldn't be used. Use surface instead. This feature was deprecated after v3.18.0-0.1.pre. Try replacing the use of the deprecated member with the replacement.

like image 157
Cabdirashiid Avatar answered Oct 14 '25 15:10

Cabdirashiid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!