Debug mode banner is not removed - flutter

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(),
);
}
}

Related

Getx controller not found even after Get.put() | Flutter | Getx

"YouController" not found. You need to call "Get.put(YouController())" or
"Get.lazyPut(()=>YouController())"
Getting this error even after I have Get.put() before coming to the screen.
Any Idea?
You can try this:
create a file named initial_bindings.dart in your lib folder. Then add this snippet to it.
import 'package:get/get.dart';
class InitialBinding implements Bindings {
#override
void dependencies() {
Get.lazyPut<YouController>(() => YouController(),fenix: true);
}
}
Then in your main.dart, add this line into your GetMaterialApp.
class MyApp extends StatelessWidget {
const MyApp({super.key});
#override
Widget build(BuildContext context) {
return GetMaterialApp(
initialBinding: InitialBinding(), // add this line
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
);
}
}
Then whenever you want to access the controller, you can just use Get.find<YourController>() to use it.

How can i use Provider in flutter_native_splash package?

I want to get user's data from server and set State, when app is loading. so I use flutter_native_splash package and provider for app. the provider doesn't work.
stock_notifier.dart
class StockCodeNotifier extends ChangeNotifier {
final List<StockModel> _stocks = [];
String _stockCode = '';
String get stockCode => _stockCode;
void getStocks() {
List<StockModel> data = allStocks;
_stocks.clear();
_stocks.addAll(data);
_stockCode = _stocks[0].code;
notifyListeners();
}
main.dart
void main() {
WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
runApp(MyApp());
Provider.of<StockCodeNotifier>(context).getStocks();
FlutterNativeSplash.remove();
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return ChangeNotifierProvider<StockCodeNotifier>(
create: (_)=>StockCodeNotifier(),
child: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: Home(),
),
);
}
}

I have created an app in flutter, but whenever i press the back button it redirects me back to the pages i had open instead of previous pages

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(),
);
}
}

Flutter Dark mode statusbar color

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)
);

Recommended Dark/Light or custom Theme implementation in Flutter Cupertino

I’m currently implementing an iOS style app in flutter using the CupertinoApp class and Cupertino widgets. Now I would like to implement a different Theme for the application (like feedly did), so that the user can switch between both during runtime.
Unlike a MaterialApp, CupertinoApp has no property to set the theme.
MaterialApp with theme property:
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
CupertinoApp without theme property:
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return CupertinoApp(
title: 'Flutter Demo',
// theme: ThemeData(
// primarySwatch: Colors.blue,
// ),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
It looks like sb. is working on a CupertinoTheme which actually seems to be a Theme for a MaterialApp and not for a CupertinoApp.
What's the recommended way to define themes and change them during runtime in a Cupertino style app (e.g. Dark and Light Theme)?
First of all CupertinoThemeData is an alternative for ThemeData:
import 'package:flutter/cupertino.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return CupertinoApp(
title: 'Flutter Demo',
theme: CupertinoThemeData(),
home: MyHomePage(),
);
}
}
CupertinoThemeData has a 'raw' property which contains these properties:
Brightness, primaryColor, primaryContrastingColor, textTheme and so on.
Would you want to choose either dark or light? that's too easy!!
CupertinoThemeData.raw(Brightness.light)
CupertinoThemeData.raw(Brightness.dark)
but if you want to change it during runtime you should write a function:
CupertinoThemeData generalTheme(Brightness brightness) {
CupertinoThemeData _basicCupertinoTheme = CupertinoThemeData.raw(
brightness,
...
}
As you see, you can send an argument to function but don't forget to use setState method.
For more info check out CupertinoThemeData.raw constructor
you can use the following package to control dark and light themes, also the theme is saved directly into shared preferences so when you reopen the application, the latest theme you chose will be loaded,use the package as provided in the read me section.
https://pub.dartlang.org/packages/dynamic_theme