skip to Main Content

In flutter:

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(
      title: 'My Super App',
      theme: ThemeData(
        useMaterial3: true,
        scaffoldBackgroundColor: Colors.white,
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
      ),
      home: const MyHomePage(),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return const Text("hello");
  }
}

I don’t see why this is not having the white background I have set with scaffoldBackgroundColor. Here is what I obtain…

enter image description here

3

Answers


  1. In MyHomePage widget, wrap Text with with scaffold .
    You can refer here from the docs.

    Login or Signup to reply.
  2. Update your MyHomePage Like this

    class MyHomePage extends StatelessWidget {
      const MyHomePage({super.key});
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(body: Text("Hello"),);
      }
    }
    
    Login or Signup to reply.
  3. You just declare the Scaffold background color but, forgot to use Scaffold Widget in your code.

    class MyHomePage extends StatelessWidget {
      const MyHomePage({super.key});
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: const Text('hello'),
        );
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search