Advertisement

Responsive Advertisement

create your flutter default template


In this post, I am gonna talk about the IntelliJ live template feature for making our custom flutter template because In flutter we always need to write the same class hierarchy for all classes so this feature will help you to automate your default code template.

after saving our code template we need only to write the template name and press the tab key then the template created by Intellij.

So let's go step by step:).

step 1.

create your flutter project following file -> new -> project -> select flutter

Here I am using java for android and objective-c for ios


step 2

then clear your main class that created with a project in the lib folder.

add what your template needs code sniff. I have created the most basic flutter class that I am gonna use as my template below I added my default code template.


import 'package:flutter/material.dart';

void main() {
runApp(new MaterialApp(
home: new MyApp(),
));
}

class MyApp extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _State();
}

}

class _State extends State<MyApp> {

@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Default Template"),
),
body: new Container(
padding: new EdgeInsets.all(32.0),
child: new Center(
child: new Column(
children: [
new Text("devthink.net")
],
),
),
),
);
}

}

 

and now we want to use the above code as a template.


step 3

go to file -> setting

then search live template

after select flutter from the menu and click + button and select live template.


then select applicable context as Dart from the menu and give abbreviation and description for your template. (here abbreviation used as a key for our template which means in your new class write your abbreviation and click the tab button then the template code will be added to a class.)

then copy and paste your code template to the template text area. 

The finally filled template looks like below.


then click apply and ok. your template is ready.




Post a Comment

0 Comments