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.`
Tejas Panchratna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
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!'),
),
),
);
Override the appBarTheme
in ThemeData
to have the desired color:
theme: ThemeData(
appBarTheme: AppBarTheme(
backgroundColor: Colors.lime,
),
useMaterial3: true,
brightness: Brightness.light,
),
1
Most probably the problem is with the line of logical elevation provider.Check whether **defaultTargetPlatform ** is got a value