Open In App

Flutter – Elevation in AppBar

In Flutter, you can set the elevation of the AppBar using the elevation property. The elevation controls the shadow effect displayed below the AppBar. Here’s an example code snippet to set the elevation of the AppBar:

AppBar(
         title: Text('Elevation'),
         elevation: 20,
       ),

In the above code snippet, the elevation property is set to 20. You can adjust the value to increase or decrease the elevation of the AppBar. A higher value will produce a more prominent shadow effect.



Note: The elevation property is only available on Android and web platforms. On iOS, the AppBar has a fixed elevation of 0.0, and the elevation property has no effect.

Example of Default Elevation of the AppBar




import 'package:flutter/material.dart';
  
void main() {
  runApp(RunMyApp());
}
  
class RunMyApp extends StatelessWidget {
  const RunMyApp({super.key});
  
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(primarySwatch: Colors.green),
      home: Scaffold(
        appBar: AppBar(
          title: Text('Elevation'),
    
        ),
        body: Center(
          child: Text('Default Elevation'),
        ),
      ),
    );
  }
}

Output:



 

Code Explanation:

Example of Elevation 20 of the AppBar




import 'package:flutter/material.dart';
  
void main() {
  runApp(RunMyApp());
}
  
class RunMyApp extends StatelessWidget {
  const RunMyApp({super.key});
  
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(primarySwatch: Colors.green),
      home: Scaffold(
        appBar: AppBar(
          title: Text('Elevation'),
          elevation: 20,
        ),
        body: Center(
          child: Text(' Elevation 20'),
        ),
      ),
    );
  }
}

Output:

 

Code Explanation:


Article Tags :