Last active
October 23, 2020 09:24
-
-
Save jack24254029/f3302ecf10045ae6172984495a7a39a4 to your computer and use it in GitHub Desktop.
Use different color of the status bar and color of the app bar.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter/services.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
routes: <String, WidgetBuilder>{ | |
'Page 1': (BuildContext context) => MyHomePage(), | |
'Page 2': (BuildContext context) => MyHomePage2(), | |
}, | |
theme: ThemeData( | |
visualDensity: VisualDensity.adaptivePlatformDensity, | |
), | |
home: MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return AnnotatedRegion<SystemUiOverlayStyle>( | |
value: SystemUiOverlayStyle( | |
statusBarColor: Colors.black, | |
statusBarBrightness: Brightness.dark, | |
statusBarIconBrightness: Brightness.light, | |
), | |
child: Scaffold( | |
appBar: Platform.isIOS | |
? AppBar( | |
brightness: Brightness.dark, | |
elevation: 0.0, | |
backgroundColor: Colors.black, | |
toolbarHeight: 0.0, | |
) | |
: null, | |
body: SafeArea( | |
child: Column( | |
children: [ | |
AppBar( | |
title: Text('Page 1'), | |
backgroundColor: Colors.green, | |
), | |
Center( | |
child: MaterialButton( | |
onPressed: () { | |
Navigator.pushNamed(context, 'Page 2'); | |
}, | |
child: Text('Next Page'), | |
), | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
} | |
class MyHomePage2 extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return AnnotatedRegion<SystemUiOverlayStyle>( | |
value: SystemUiOverlayStyle( | |
statusBarColor: Colors.white, | |
statusBarBrightness: Brightness.light, | |
statusBarIconBrightness: Brightness.dark, | |
), | |
child: Scaffold( | |
appBar: Platform.isIOS | |
? AppBar( | |
brightness: Brightness.light, | |
elevation: 0.0, | |
backgroundColor: Colors.white, | |
toolbarHeight: 0.0, | |
) | |
: null, | |
body: SafeArea( | |
child: Column( | |
children: [ | |
AppBar( | |
title: Text('Page 2'), | |
backgroundColor: Colors.red, | |
), | |
Center( | |
child: Text('Page 2'), | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment