-2

I'm new to flutter. working on a chat app. I have created a app bar but the colors I added in main.dart not display. it just display as default blue color. how to correct??

enter image description here

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      //title: 'Profile Section',
      theme: ThemeData(
        primaryColor: Color(0xff075e54),
        accentColor: Color(0xff128C7E)),
        home: Homescreen(key: null),

    );
  }
}

homescreen.dart

import 'package:flutter/material.dart';


class Homescreen extends StatefulWidget {
  Homescreen({ Key? key }) : super(key: key);


  @override
  _HomescreenState createState() => _HomescreenState();
}

class _HomescreenState extends State<Homescreen> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Whatsapp Clone"),
        actions: [
          IconButton(icon: Icon(Icons.search), onPressed: () {}),
          IconButton(icon: Icon(Icons.more_vert), onPressed: () {}),
    ],
    ),
    );
  }
}

1 Answers1

0

Use this, as your code. It should work.

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  final ThemeData theme = ThemeData(); //You need to make a var, that works as ThemeData

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      //title: 'Profile Section',
      theme: theme.copyWith(
        colorScheme: theme.colorScheme.copyWith(primary: Color(0xff075e54),secondary: Color(0xff128C7E), //Then use it with colorScheme.
     ),
     ),
     home: Homescreen(key: null),
    );
  }
}
CidQu
  • 412
  • 6
  • 13
  • 1
    wow works thank you so much –  Feb 04 '22 at 18:33
  • 1
    @Maharabage if it is works, can you please confirm it with the green tick so people will understand and don't try to add new codes here again. – CidQu Feb 04 '22 at 18:35