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
Can you try with below solution… Hope it will help for you…
Override the
appBarTheme
inThemeData
to have the desired color: