Home > Software design >  what is the alternative for accentColor Flutter
what is the alternative for accentColor Flutter

Time:02-05

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: () {}),
    ],
    ),
    );
  }
}

CodePudding user response:

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),
    );
  }
}
  •  Tags:  
  • Related