I could not find an answer to my question, basically all similar situations are related to rebuilding widgets that use MediaQuery (but not in my case). When I tap on the TextField, the keyboard appears, after which the builder inside the MaterialApp.router is called dozens of times. Is it possible to avoid so many builder calls?
main.dart:
import 'package:flutter/material.dart';
import 'package:routemaster/routemaster.dart';
final routes = RouteMap(
onUnknownRoute: (route) => const Redirect("/"),
routes: {
'/': (_) => const MaterialPage(child: FirstPage()),
},
);
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp.router(
builder: (context, widget) {
debugPrint("Info: MaterialApp.router Build");
return widget!;
},
routeInformationParser: const RoutemasterParser(),
routerDelegate: RoutemasterDelegate(
routesBuilder: (context) {
debugPrint("Info: Router Build");
return routes;
},
),
);
}
}
class FirstPage extends StatelessWidget {
const FirstPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
debugPrint("Info: FirstPage Build");
return Scaffold(
body: Column(
children: const [
Padding(
padding: EdgeInsets.only(top: 200),
child: TextField(),
),
],
),
);
}
}
Console:
Launching lib/main.dart on iPhone 13-2 in debug mode...
Running Xcode build...
Xcode build done. 14,4s
Debug service listening on ws://127.0.0.1:62493/BzKbBCNai2Q=/ws
Syncing files to device iPhone 13-2...
flutter: Info: MaterialApp.router Build
flutter: Info: Router Build
flutter: Info: FirstPage Build
flutter: Info: MaterialApp.router Build // opening keyboard
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build
flutter: Info: MaterialApp.router Build