The simple template app created using the flutter create command has its uses. For a beginner it can be helpful in showing the simple use cases and state management of Flutter. But sooner or later the default template becomes more of a hassle then a help. Deleting the lines of comments, renaming the horrid widget names, and transitioning away from StatefulWidgets to the BLoC design pattern. Often times, you end up just deleting the original main.dart file and starting over — which makes you question why the template is there at all.

But it doesn’t have to be this way.

While searching for another tool, I stumbled across this templates folder.

Navigate to

{your-flutter-install}/packages/flutter-tools/templates/app/

Here you will find the default template used when running flutter create or creating a New Flutter Project in Android Studio or IntelliJ. You can edit any of these files, but /lib/main.dart.tmpl is the real goldmine. A lot of the text here will look unfamiliar because it handles the formatting of the file and what to leave in or out when you run flutter create with specific options.

But if you stick with what you know, you can easily find and then edit code like this.

class MyApp extends StatelessWidget {

// This widget is the root of your application.

@override Widget build(BuildContext context) {

return MaterialApp(

title: ‘Flutter Demo’,

theme: ThemeData(

// This is the theme of your application.

//

// Try running your application with “flutter run”. You’ll see the

// application has a blue toolbar. Then, without quitting the app, try

// changing the primarySwatch below to Colors.green and then invoke

// “hot reload” (press “r” in the console where you ran “flutter run”,

// or simply save your changes to “hot reload” in a Flutter IDE).

// Notice that the counter didn’t reset back to zero; the application

// is not restarted.

primarySwatch: Colors.blue,

),

home: MyHomePage(title: ‘Flutter Demo Home Page’),

);

}

}

I went through the entire file to remove the comments and take the My out of the widget names. I also changed the StatefulWidget to a stateless widget and transitioned the template app to the BLoC design pattern.