skip to Main Content

HereIsAScreenshotOfMyCodeAndSimulator` I am creating a simple Flutter app with an AppBar. I expect the AppBar to be displayed in lime color as specified in the ThemeData, but it does not appear at all. The body text "Hello, Flutter!" is displayed correctly. I have tried restarting VSCode, running flutter clean, and testing on different simulators, but the issue persists.

Here is my code:

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(primarySwatch: Colors.lime),
      home: HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Drawer App"),
        elevation: defaultTargetPlatform == TargetPlatform.android ? 5.0 : 0.0,
      ),
      body: Center(
        child: Text("Hello, Flutter!"),
      ),
    );
  }
}

What I have tried:

Restarting VSCode
Running flutter clean
Testing on different simulators
Output:

The "Hello, Flutter!" text is displayed, but the AppBar is not visible.`

2

Answers


  1. Can you try with below solution… Hope it will help for you…

     return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('My App'),
        ),
        body: Center(
          child: Text('Hello, World!'),
        ),
      ),
    );
    
    Login or Signup to reply.
  2. Override the appBarTheme in ThemeData to have the desired color:

    theme: ThemeData(
        appBarTheme: AppBarTheme(
          backgroundColor: Colors.lime,
        ),
        useMaterial3: true,
        brightness: Brightness.light,
      ),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search