How do you change the status bar text color to black when its in dark mode? I can't find an answer for dark mode only in flutter.
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Fry',
theme: ThemeData(),
darkTheme: ThemeData(
),
home: Loader(),
routes: {
MainMenu.id : (context) => MainMenu(),
},
debugShowCheckedModeBanner: false,
);
}
}
for iOS open Info.plist, it is under ios/Runner and add that;
<key>UIUserInterfaceStyle</key>
<string>Light</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
and import services library to your main.dart file;
import 'package:flutter/services.dart';
and use this to change the status bar color;
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(statusBarBrightness: Brightness.light)
);
Related
I'm using webview_flutter to display a site. The problem is, the site is opening in dark mode. I tried setting MaterialApp theme and darkTheme properties to ThemeData.light(), but the webview is not respecting it and taking Device's default theme. Switching device theme reflects in the webview.
How to enforce light/dark theme to the WebView widget explicitly?
Here a main.dart snippet
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
//please explain this one as well
// SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
// statusBarBrightness: Brightness.dark) // Or Brightness.dark
// );
return MaterialApp(
themeMode: ThemeMode.light,
theme: ThemeData.light(),
darkTheme: ThemeData.light(),
debugShowCheckedModeBanner: false,
title: 'Flutter site',
home: SafeArea(
child: WebViewExample(),
),
);
}
}
class WebViewExample extends StatefulWidget {
#override
WebViewExampleState createState() => WebViewExampleState();
}
class WebViewExampleState extends State<WebViewExample> {
#override
void initState() {
super.initState();
// Enable hybrid composition.
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
// if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) { }
}
#override
Widget build(BuildContext context) {
return WebView(
javascriptMode: JavascriptMode.unrestricted,
initialUrl: 'https://flutter.dev.',
);
}
}
I am working on a Flutter app and want to hide the debug mode banner.
This is my code for main.dart:
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError;
//FirebaseCrashlytics.instance.crash();
runApp(new MaterialApp(
debugShowCheckedModeBanner: false,
home: new MyApp(),
));
}
The debug mode banner is not removed, it is shown as always.
What do I need to change to get it removed?
Debug banner does not remove from main method, you just follow the example and you bind your MyApp() with the MaterialApp()
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: NextPage(),
);
}
}
I am very new to flutter. Learning the basics. But the back button is not working as it should in the app.
This my main.dart file:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primaryColor: Colors.orange
),
debugShowCheckedModeBanner: false,
home: HomePage(),
);
}
}
I have been working on dynamic dark and light mode feature in flutter.
I want to change the app's theme as dark theme or light theme when i am changing the mobile system's dark/light mode from system settings.
But, I'm not able to change the app's dark or light mode based on Mobile System's light or dark mode.
I'm using the following code.
main.dart
import 'package:flutter/material.dart';
import 'package:flutterrookieapp/provider/ThemeProvider.dart';
import 'package:flutterrookieapp/utils/AppTheme.dart';
import 'package:provider/provider.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(
create: (context) => ThemeProvider(
MediaQuery.of(context).platformBrightness == Brightness.dark
? darkTheme
: lightTheme),
)
],
child: Consumer<ThemeProvider>(
builder: (temp, theme, _) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Sample',
theme: MediaQuery.platformBrightnessOf(context) == Brightness.dark
? darkTheme
: lightTheme,
home: HomePage(),
);
},
),
);
}
}
}
ThemeProvider.dart
import 'package:flutter/material.dart';
class ThemeProvider with ChangeNotifier {
ThemeData _themeData;
ThemeProvider(this._themeData);
ThemeData getTheme() => _themeData;
setTheme(ThemeData themeData) async {
this._themeData = themeData;
notifyListeners();
}
}
you can use in the MaterialApp the darkTheme or theme
it's always from the mobile system setting
MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Sample',
darkTheme: darkTheme,
theme: lightTheme,
home: HomePage(),
),
How can I change the color shown in the app switcher of Android. Right now the color comes up with a gray background, but I want it to be red.
This is the app code.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
color: Colors.red,
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Material(
child: Text('Check color in app switcher.'),
),
);
}
}
The color parameter of MaterialApp has no effect.
If you are using the MaterialApp you would use the color attribute to change the color of the app bar in the switcher.
You could also use the SystemChrome.setApplicationSwitcherDescription method which you would find in package:flutter/services.dart