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