Development/Flutter (Dart)

[SOLVED][Flutter3] 'backgroundColor' is deprecated and shouldn't be used. Use colorScheme.background instead. This feature was deprecated after v3.3.0-0.5.pre. Try replacing the use of the deprecated member with the replacement.

Tradgineer 2023. 12. 30. 16:08

 

 

1. 문제 발생

 

backgroundColor 가 deprecated되어 발생하는 문제입니다.

'backgroundColor' is deprecated and shouldn't be used. Use colorScheme.background instead. This feature was deprecated after v3.3.0-0.5.pre. Try replacing the use of the deprecated member with the replacement.

 

import 'package:clone_pomodoro/screens/home_screen.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        backgroundColor: Color(0xFFE7626C),
        textTheme: const TextTheme(
          displayLarge: TextStyle(
            color: Color(0xFF232B55),
          ),
        ),
        cardColor: const Color(0xFFF4EDDB),
      ),
      home: const HomeScreen(),
    );
  }
}

 

 

 

 

 

2. 해결방법

 

// 수정 전
backgroundColor: Color(0xFFE7626C),

// 수정 후
scaffoldBackgroundColor: const Color(0xFFE7626C),

 

import 'package:clone_pomodoro/screens/home_screen.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        scaffoldBackgroundColor: const Color(0xFFE7626C),
        textTheme: const TextTheme(
          displayLarge: TextStyle(
            color: Color(0xFF232B55),
          ),
        ),
        cardColor: const Color(0xFFF4EDDB),
      ),
      home: const HomeScreen(),
    );
  }
}