Appbar title under status bar flutter - android

I am relatively new to flutter so I don't know why my appbar appears like this
Here is the main.dart file
import 'package:testapp/test_page.dart';
import 'package:flutter/material.dart';
void main() {
runApp(Home());
}
class Home extends
StatelessWidget {
#override
Widget build(BuildContext
context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Test App',
theme: ThemeData(primaryColor: Colors.purple),
home: TestPage(),
);
}
}
Here is my testpage.dart
import 'package:flutter/material.dart';
class TestPage extends
StatelessWidget {
#override
Widget build(BuildContext
context) {
return Scaffold(
primary: false,
appBar: AppBar(
title: Text(' Test app'),
),
body: Center(child: Text('Example Test')),
);
}
}
I tried using SafeArea it didn't work. Thank you

here is what i solved similar issue.
Simply wrap your Scaffold widget with SafeArea Widget
SafeArea(
child: Scaffold()
)
You can find more detail about SafeArea Widget in this link
Flutter SafeArea Widget
Hope it will help
Happy coding

You have primary property set to false.
Whether this scaffold is being displayed at the top of the screen.
If true then the height of the appBar will be extended by the height
of the screen's status bar, i.e. the top padding for MediaQuery.
https://api.flutter.dev/flutter/material/Scaffold/primary.html

change the primary value to true and tell me result:
Scaffold(
primary: true, // this line
appBar: AppBar(......
Edit:
MaterialApp cant be a child of statelessWidget. use it as the main Widget
runApp(MaterialApp(
......
))

Thank you much guys, I created a new project then I realised it was caused by a bug from one of the libraries I installed. It's totally fixed now ♥️

Related

How to access the app's "in-time" icon in flutter(dart code)?

I want to display the app's icon in my flutter app
I have an app with many icons since I use flutter_launcher_icons
research with google and stackoverflow
I hope you already have set launcher icon if yes then now you can use Use https://pub.dev/packages/application_icon
import 'package:application_icon/application_icon.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
// use AppIcon to show your application icon
child: AppIconImage(),
),
),
);
}
}
Or directly access launcher icon from asset folder

No MediaQuery widget ancestor found. Scaffold widgets require a MediaQuery widget ancestor

I am new to flutter, BUILT an app showing graphs in flutter. When i run the code a red screen is appearing showing the above error
No MediaQuery widget ancestor found. Scaffold widgets require a MediaQuery widget ancestor.
I have cleared all the errors except this one.
Full link of the code
Check you main.dart, and in the MyApp (Or whatever you named it) class, you should wrap it with MaterialApp. It should fix the problem.
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Graphn',
home: GraphScreen(),
);
}
}
Wrap your scaffold to MatertialApp or you can make a class and in that class call GraphScreen like this
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: GraphScreen(),
);
}
}

Why doesn't anything show up the body of this flutter scaffold?

The class in question is invoked from another page with the line
onPressed: () {
Navigator.push(context, MaterialPageRoute(
builder: (context) =>
ProPage(iD: bestRatedPros[index]["ID"])));
},
Where bestRatedPros is a list of maps with the variable iD for the following class -
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class ProPage extends StatefulWidget {
ProPage({Key key, this.iD}) : super(key: key);
final iD;
#override
_ProPageState createState() => _ProPageState(iD);
}
class _ProPageState extends State<ProPage> {
int iD;
_ProPageState(this.iD);
#override
void initState() {
super.initState();
}
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.amber,
extendBodyBehindAppBar: true,
appBar: AppBar(
iconTheme: IconThemeData(
color: Colors.white, //change your color here
),
elevation: 0,
backgroundColor: Colors.amber
),
body:
Text("EWFWEFEWEWFWEF",style: TextStyle(color: Colors.black))
);
}
}
The getDataFromBackend function and
all the variables associated with it was meant to be within the body. But Nothing shows up in the body no matter what it is. Even a simple Text widget doesn't. I'm only trying to pass the variable iD from one page to the other without complicating things. The Run log doesn't show any Errors or warnings.
Arun,
See below where your Text is:
Reason for that is that you specified:
extendBodyBehindAppBar: true,
on your Scaffold, so body is expanded and top part of it is hidden behind AppBar

how can I build Widgets using flutter?

View screen shot here
I need to build this kind of widget to my flutter application.The widget should be can bring across the screen. is its possible? Then How can I do that?
Thanks in advance!
Actually, Flutter can't create this type of widget (widget that you can add on your Home Screen) because Flutter uses his own custom rendering engine.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text(“First Widgets")),
body: myWidget(),
),
);
}
}
Widget myWidget() {
return Text(
"Hello, World!",
);
}
}

Changing the TaskDescription bar color with Flutter

Is there a way to change the TaskDescription bar color in a Flutter app?
Here is a link to what I am trying to achieve.
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);
#override
Widget build(BuildContext context) {
// Change the status bar color
FlutterStatusbarcolor.setStatusBarColor(Colors.white);
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'SMS 2 Server',
color: Colors.white,
theme: ThemeData(
//brightness: Brightness.light,
primarySwatch: primaryWhite,
inputDecorationTheme: InputDecorationTheme(
)
),
home: HomePage(),
);
}
}
you can do like this
Scaffold(
appBar: new AppBar(
backgroundColor: new Color(Color you want),
),
);
or
theme: ThemeData(
primaryColor: YourExpected Color,
)
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
// put the color in here
color: Colors.red,
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Home(),
),
),
);
}
}
Go to the main. dart file and add your color in color attribute under MaterialApp widget
This is not something that Flutter handles. You have to do it from the Android side.
For changing the TaskDescription color of your app, you have to do this in your MainActivity (my example is using Kotlin, but is almost the same with Java).
// Import TaskDescription
import android.app.ActivityManager
class MainActivity: FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
GeneratedPluginRegistrant.registerWith(this)
// Change the color (it's not available on versions before Lollipop)
Timer("ChangingTaskDescriptionColor", false).schedule(1000) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
val taskDescription = ActivityManager.TaskDescription(null, null, Color.RED)
setTaskDescription(taskDescription)
}
}
}
Remember to define the color on your colors.xml.
This changes the bar color. You can also set a custom title and icon. But the text color is automatically setted by Android (black or white only).
More information on TaskDescription here
PS: Keep in mind this is something that is not longer available on Android P (don't remember Oreo) as it only shows an Icon. So you should test this on newer versions to be sure it doesn't crash. Maybe check if the API <= than something too.
UPDATE
After trying to make this work on Flutter, I came to the conclusion that the TaskDescription is being override on some point after the first onResume() lifecycle method call. So the only way I could get the result we need, is to use a delay.
Also, it didn't accept the color value from xml, so I've ended using android.graphics.Color.
I've update my code example to show you what I did. And here's the result!
Try use primaryColor attribute of your ThemeData
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'SMS 2 Server',
color: Colors.white,
theme: ThemeData(
//brightness: Brightness.light,
primarySwatch: primaryWhite,
primaryColor: Colors.blue,
inputDecorationTheme: InputDecorationTheme(
)
),
home: HomePage(),
);
If you want to give the title a color of its own, wrap the Text widget with a Container widget and give the Container a color property. eg.
Scaffold(
appBar: AppBar(
title: Container(
color: Colors.red,
child: Text("Your Title")
),
)
)
but I believe the best way has been suggested by #akshay_shahane or #Augusto
The color param in the materialApp Widget should do the work.
In this case the color is green:
MaterialApp(
title: 'Flutter Demo',
color: Colors.green,
theme: ThemeData(
primarySwatch: Colors.orange,
canvasColor: Colors.white,
textTheme: TextTheme()),
home: MyHomePage(title: 'Home'),
);
}
This is absolutely something Flutter handles. You can see it for yourself in the code for the flutter Title widget. The problem is that, as of this writing, there is a bug in the flutter engine that has not allowed the color to be set ever since March of 2019. Soon it will work again, and you will be able to do the following:
Add this to the top of your .dart file:
import 'package:flutter/services.dart';
Add something like this to another part of your app. Do keep in mind that if any of your base widgets like MaterialApp or Scaffold use the Title widget, your setting here may be overwritten if your code is run before the code in those widgets. In that case, you can put the code below into a button or something like that to try it out:
SystemChrome.setApplicationSwitcherDescription(
ApplicationSwitcherDescription(
label: "App Title",
primaryColor: Colors.black.value,
)
);
Again, I will reiterate that this does not work right now because of a bug. If you go to the trouble of compiling the engine yourself with that patch applied (which is not for the faint of heart), you can have it working immediately, but the compilation process for the flutter engine is not very easy to set up.

Categories

Resources