Background: Since creating a Dart File in Android Studio is a blank SLATE and requires a bunch of repetitive code to be written each time, is it possible to automatically generate a fixed template like Java Class?
Customize file templates
Android Studio set path: Android Studio | Preferences | search Templates | File and Code Templates | Dart File setup steps are as follows:
* * * template
import 'package:flutter/material.dart';
/ * * *@author[${USER}]
* @version[Create DATE, ${DATE} ${TIME}] *@function${DESCRIPTION}] **/
class ${NAME}Page extends StatefulWidget {
const ${NAME}Page({Key? key}) : super(key: key);
@override
_${NAME}PageState createState() => _${NAME}PageState();
}
class _${NAME}PageState extends State<${NAME}Page> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("${NAME}"),),body: Center(
child: Column(),
)// This trailing comma makes auto-formatting nicer for build methods.); }}Copy the code
Method of use
supplement
You can customize the template code or add templates to suit your needs. This approach works for almost all compilers.