how to add a color to flutter app code example

Example 1: how to give your app background colour in flutter

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Welcome to Flutter',
      home: Scaffold(
        backgroundColor: Color(0xff00BCD1),
        appBar: AppBar(
          title: Text('Flutter Screen Background Color Example'),
        ),
        body: Center(child: Body()),
      ),
    );
  }
}

/// This is the stateless widget that the main application instantiates.
class Body extends StatelessWidget {
  
  Widget build(BuildContext context) {
    return Text('How Are You?');
  }
}

Example 2: how to change appbar color in flutter

appBar: AppBar(
      title: const Text('Example'),
      backgroundColor: Colors.black,
    ),

Tags:

Dart Example