iam new at flutter iam trying to add CircularProgressIndicator at page loading and then change state but its seems like it freeze on navigation
Main.Dart
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: AppString.appName,
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: Colors.grey.shade900,
),
home: const DummyScreen(),
);
}
}
Navigation Screen
class DummyScreen extends StatelessWidget {
const DummyScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: TextButton(
child: const Text("Navigate"),
onPressed: (){
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const AnotherDummyScreen()));
},
),
),
);
}
}
CircularProgressIndicator Screen
class AnotherDummyScreen extends StatelessWidget {
const AnotherDummyScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const Scaffold(
body: Center(
child: CircularProgressIndicator(),
),
);
}
}
CircularProgressIndicator Widget Should be more smoothly at page Load as it take a while to start animate
2
Answers
Rebuild app and try or try on other device.
I assume you run this on an emulator or are performing any other heavy performance tasks either in your app or on the device?
Why you have to test on real device taken from the flutter docs:
"Jank" can have multiple reasons. The you provided code looks totally fine.
If you are running this on a real device I recommened to take look at concrete profiling in flutter. You can do for instance:
flutter run --profile
Note that you also should do profiling always on a real device.
With profiling you can then identify the root issue of your jittering animation. The link from the flutter docs above also does provide a good understanding on how profiling works and how to interpret everything. It also provides information on how to use the flutter dev tools, VScode and Android Studio for further performance analysis.