I'm trying to make my app performant.
I'm using dart devtools and when i check the graph I see that there is some shader compilation detected when launching the app for the first time, I thought that my app has a problem but i tried to run the code that flutter provides us when creating a new project and boom the result was the same.
I want to know if there is someone that encountred the same problem ?
Ps : i tested the app on a real device with os Android 12 and CPU ARM X64.
there is my code :
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
#override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'Sample App',
home: MyHomePage(
title: 'App',
),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key, required this.title});
final String title;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Center(
child: Column(
children: const [
Text('hello'),
],
),
),
);
}
}
As I understand your problem, you want to reduce the time your app needs to start and found the shader compilation to be a big part of it. If that understanding is correct, this might help:
First, you can not "disable" shader compilation, every flutter application needs to compile the shaders for rendering, but it heavily depends on your application, how much time that takes (many animations for example are bad here)
Second, since Flutter 1.20, you can use the SkSL warmup to reduce the startup time for compiling your shaders. The idea being, that you compile the shader once and save it for faster startup times.
You can test this feature while in development with
flutter run --cache-sksl
this will take more time than before, but afterwards, your flutter run commands will be faster.
If you want to build your application with SkSL warmup, you have to write the SkSL shaders into a file by pressing "M" while in the command line of flutter run, then you can use:
flutter build ios --bundle-sksl-path flutter_01.sksl.json
to build the application. More information can be found here.
I tested this with the small program you sent, for normal startup it needed 25.9ms for the shader compilation, caching the sksl file needed 225.9ms, and flutter run afterwards needed 9.6ms for the shaders. Therefore caching sksl made it about 63% faster (it was only one short test, so the results are no medians or anything, so the meaningfulness of this test is debatable).
Lastly, you should always test your performance in release builds, not in debug mode. Debugging your application has a large overhead and much worse performance than released applications. Have a look at Flutter build modes for more information.
I want to create a PWA using Flutter web but on iPhone X Models the top notch gets cut off.
Expected:
Actual:
The code I used:
import 'package:flutter/cupertino.dart';
void main() {
runApp(CupertinoApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
home: CupertinoPageScaffold(child: Center(child: Text("PWA")))));
}
I tried changing the meta tag in the index.html to:
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"></meta>
But this does not support dark mode.
Does any one got a better idea to solve this?
You can wrap your widget in safe area to prevent your app having such problems.
SafeArea(
child: Text("PWA"),
),
Happy coding...
I am trying to do a responsive webapp and everything was working fine debugging it on the desktop firefox and I did the entire layout with the switch device option in the debug tools, but when I uploaded to an HTTP server and access it through my phone I get this screen
On chrome I have no problems and everything displays just right, on firefox on the other hand I have that weird blank space... At chrome that space was occupied by the "add to the homescreen" prompt, maybe that has something to do?
Any ideas would be greatly apreciated. I'm leaving the code just in case it helps...
void main() => runApp(MyApp2());
class MyApp2 extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Material App',
home: Scaffold(
appBar: AppBar(
title: Text('Material App Bar'),
),
body: Container(
color: Colors.red,
// child: Text('Hello World'),
),
),
);
}
}
I guess its useful to say that on chrome I get the expected behaviour of getting the full screen red except for the AppBar
Add to Homescreen button is feature of PWA so you should dive into index.html probably. Can you debug your Firefox Mobile and play with css a little bit. You can check official Firefox Remote Debugging Docs.
I'm building my first web project.
So the project is structured like so:
Web: Is a web site, one of the pages (RetailerAccess) is an actual app that should be compatible with all devices.
In order to do so I use platform check in main() and return the proper screen.
home: kIsWeb
? Stack(
children: [
Container(
// color: Colors.white,
child: AnimatedBackground(),
),
LayoutTemplate()
],
)
: RetailerAccess());
It works as expected.. When running on browser shows the web page and you can navigate to RetailerAccess while if running on iPad starts directly on RetailerAccess.
So far so good.
The weird part is that text widgets are drawn with a double green underline where running on device while when running on browser are drawn normally.
Are you aware of any bug that makes it behave like this or is there something I should set in a specific way?
I tried running it in Release mode on an old iPad 3 running iOS 9.3.5 but no changes..
Thank you very much for your help.
Update:
I realised I don't have a Scaffold in RetailerAccess wrapped it with a Material widget and it solved it.
Shouldn't a theme been passed to RetailerAccess anyways?
You are getting the error because you don't have a scaffold widget.
Try the code below:
It works perfectly:
home: kIsWeb
? Scaffold(
Stack(
children: [
Container(
// color: Colors.white,
child: AnimatedBackground(),
),
LayoutTemplate()
],
)
),
: Scaffold(
RetailerAccess()
);
I hope this helps.
I have two files, main.dart and sections.dart.
I have defined a few widgets in section.dart and used them in main.dart file, when I run flutter run command changes are displayed on screen, but when I press R to hot reload, nothing changes on screen.
main.dart:
import 'package:flutter/material.dart';
import 'sections.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Share IDEASS',
home: Scaffold(
appBar: AppBar(
title: Text('IDEASs'),
),
body: ListView(
children: [
labelsSection,
],
),
),
);
}
}
Sections.dart:
import 'package:flutter/material.dart';
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
title: 'Share IDEAS',
);
}
}
Column labelSectionMethod(color,IconData icon, String label,String numbers){
return Column(
children: <Widget>[
Icon(icon, color:color),
Container(
child: Text(label,
style: TextStyle(color: color
),
),
),
Container(
child:Text(numbers,
style:TextStyle(color:color
),
),
),
],
);
}
Widget labelsSection=Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
labelSectionMethod(Colors.red,Icons.supervised_user_circle,"IDEASS","35"),
labelSectionMethod(Colors.red,Icons.favorite,"LIKE","22"),
labelSectionMethod(Colors.red,Icons.data_usage,"STREAK","12"),
],
),
);
Maybe because I am repeating:
return MaterialApp(
title: 'Share IDEAS',
);
in sections.dart, or something to do with main function.
UPDATE:
i moved content of sections.dart file in main.dart file still hot reload is not working.
After moving a file to another directory, Android Studio changed my imports to absolute paths.
import 'file:///C:/Users/svenv/AndroidStudioProjects/sample_screen_collection/lib/welcome/reading_list_card.dart';
i had to change it to this
import 'package:samplescreencollection/components/reading_list_card.dart';
This usually happens when you have change a lot of code, added states, changed a widget from stateless to state full, etc. Preforming a hot restart (ctrl +F5) will fix this issue.
If this seems to not work still, try removing the app from your phone/simulator/emulator (closing the app, and deleting it) and running debug/flutter run again. This should fix your issue
There have been issue reported to Flutter regarding this,https://github.com/flutter/flutter/issues/17155#issue-319238844
Basically it's like Flutter is not properly identifying the changes in order to generate updated build files (my personal understanding):
Solution
Simple solution is Clean the project and rebuild it.
I'm using Android studio Android Studio 3.6, Following steps illustrate how to clean the flutter project
Navigate to Tools in navigationbar
Select Flutter > Flutter Clean
Finally Run the Project again by clicking the green playicon
Sometimes flutter gets confused with large amounts of changes, and you need to perform a restart, especially when interacting with the entire App or main function.
You can pressCtrl+C to kill the flutter run process, and try launching it again. Additionally, if you run Flutter through IntelliJ or Android Studio, the flutter plugin includes a "Hot Restart" feature which accomplishes the same thing.
My situation was - Flutter would neither hot reload nor stop on a break-point nor even provide fresh builds to Android emulator, whereas iOS was fine.
I tried suggestions from above but nothing really worked, spent a day on these things.I upgraded from Android Studio 3.x to 4.1 and nothing changed.
What worked for me was:
Create a totally new Flutter sample project.
Validate it works - new versions are deployed, debugging and hot reloads work
Transfer my project into this new project. This pretty much involved replace of the lib and .git folders and manual updates of pubspec.yaml, AndroidManifest.xml and Info.plist (manual file updates took most of the effort, but still much less time than my several day attempts to make things work again)
Verify everything works.