-
Notifications
You must be signed in to change notification settings - Fork 1
/
flutter.snippets
345 lines (323 loc) · 8.86 KB
/
flutter.snippets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# A valid snippet should starts with:
#
# snippet trigger_word [ "description" [ options ] ]
#
# and end with:
#
# endsnippet
#
# Snippet options:
#
# b - Beginning of line.
# i - In-word expansion.
# w - Word boundary.
# r - Regular expression
# e - Custom context snippet
# A - Snippet will be triggered automatically, when condition matches.
#
# Basic example:
#
# snippet emitter "emitter properties" b
# private readonly ${1} = new Emitter<$2>()
# public readonly ${1/^_(.*)/$1/}: Event<$2> = this.$1.event
# endsnippet
#
# Online reference: https://github.com/SirVer/ultisnips/blob/master/doc/UltiSnips.txt
global !p
from dartlang_snippets import ensure_import
endglobal
snippet stlss "Create stateless widget" b
class ${1:name} extends StatelessWidget {
const ${1:name}({Key? key}) : super(key: key);
@override
Widget build(BuildContext context){
return Container();
}
}
endsnippet
snippet stful "Create a stateful widget" b
class ${1:name} extends StatefulWidget {
${1:name}({Key? key}) : super (Key : key);
@override
_${1:WidgetName}State createState() => _${1:WidgetName}State();
}
class _${1:index}State extends State<${1:index}>{
@override
Widget build(BuildContext context){
return Container();
}
}
endsnippet
snippet build "part of the ui represented by this widget" b
@override
Widget build(BuildContext context){
return ${0:};
}
endsnippet
snippet customPainter "Used for creating custom paint" b
class ${0:name}Painter extends CustomPainter {
@override
void paint(Canvas canvas, Size size){
}
@override
bool shouldRepaint(${0:name}Painter oldDelegate) => false;
@override
bool shouldRebuildSemantics(${0:name})=>false;
}
endsnippet
snippet customClipper "Used for creating custom shapes" b
class ${0:name}Clippes extends CustomClipper<Path> {
@override
Path getClip(Size size){
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper)=> false;
}
endsnippet
snippet initS "Called when this object is inserted into the tree. The framework will call this method exacly once for each State object it creates" b
@override
void initState(){
super.initState();
${0:}
}
endsnippet
snippet dis "Called when this object is removed from the tree permanently. The framework calls this method when this State objec will never build again." b
@override
void dispose(){
${0:}
super.dispose();
}
endsnippet
snippet reassemble "Called whenever the application is reassembled during debbugin, for example during hot reload" b
@override
void reasssemble(){
super.reassemble();
${0:}
}
endsnippet
snippet didChangeD "Caleed when a dependency of this State object changes" b
@override
void didChangeDependencies(){
super.didChangeDependencies();
${0:}
}
endsnippet
snippet didUpdateW "Called whenever the widget configuration changes" b
@override
void didUpdateWidget(${1:Type} ${2:oldWidget}){
super.didUpdateWidge(${2:oldWidget});
${0:}
}
endsnippet
snippet listViewB "Create a scrollable linear array of widgets" b
ListView.builder(
itemCount: {1:1},
itemBuilder: (BuildContext context, int index){
return ${2:};
},
),
endsnippet
snippet listViewS "Creates a fixed-length scrollable linear array of list items separeted by separators items" b
ListView.separated(
itemCount: ${1:1},
separatorBuilder: (BuildContext context, int index){
return ${2:};
},
itemBuilder: (BuildContext context, int index){
return ${3:};
},
),
endsnippet
snippet gridView "Creates a scrollable, 2D array of widgets that are created on demand." b
GridView.builder(
gridDelegate: const SilverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: ${1:2},
),
itemCount: ${2:2},
itemBuilder: (BuildContext context, int index){
return ${3:};
},
),
endsnippet
snippet gridViewC "Creates a scrollable 2D array with fixed number of tiles in the cross axis" b
GridView.count(
crossAxisSpacing: ${1:1},
mainAxisAlignment: ${2:2},
crossAxisAlignment: ${3:2},
children: <Widget>[
${4:}
],
),
endsnippet
snippet gridViewE "Creates a scrollable, 2D array of widgets with tiles that each have a maximem cross-axit extent." b
GridView.extent(
maxCrossAxisExtent: ${1:2},
children: <Widget>[
${2:},
],
),
endsnippet
snippet customScrollV "Craetes a ScrollView that creates custom scroll, effects using slivers. If the primary argument is true, the controller must be null." b
CustomScrollView(
slivers: <Widget> [
${0:}
],
),
endsnippet
snippet streamBldr "Description" b
StreamBuilder(
stream: ${1:stream},
initialData: ${2:initialData},
builder: (BuildContext context, AsyncSnapshot snapshot){
return Container(
child: ${3:child},
);
},
),
endsnippet
snippet animatedBldr "Creates an Animated builder. The widget specified to child is passed to the builder" b
AnimatedBuilder(
animation: ${1:animation},
child: ${2:child},
builder: (BuildContext context){
return ${3:};
},
),
endsnippet
snippet stateBldr "Creates a widget that both has state and delegates its build to a callback. Useful for rebuilding specific sections of the widget tree" b
StatefulBuilder(
builder: (BuildContext context, setState){
return ${0:};
},
),
endsnippet
snippet orientationBldr "Creates a builder which allows for the orientation of the device to be specified and referencend" b
OrientationBuilder(
builder: (BuildContext context, Orientation orientation){
return Container(
child: ${3:child},
);
},
),
endsnippet
snippet layoutBldr "Similar to the builder widget except that the framework calls the builder function at layout time and provides the parent widget's constrains" b
LayoutBuilder(
builder: (BuildContext context, BoxConstrains constrains){
return ${0:};
},
),
endsnippet
snippet singleChildS "Creates a scroll view with a single child" b
SingleChildScrollView(
controller: ${1:controller},
child: Colum(
${0:},
),
),
endsnippet
snippet futureBldr "Creates a future builder. This builts itself based on the latest snapshot of interaction with a Future" b
FutureBuilder(
future: ${1:future},
initialData: ${2:initialData},
builder:(BuildContext context, AsyncSnapshot snapshot){
return ${3:};
},
),
endsnippet
snippet nosm "This method is invoked when a non-existent menthod or property is accessed" b
@override
dynamic noSuchMethod (Invocation invocation){
${1:},
}
endsnippet
snippet inheritedW "Class used to propagate information down the widget tree" b
class ${1:name} extends InheritedWidget {
${1:name}({Key? key, required this.child}) : super(key:key, child:child);
final Widget child;
static ${1:name}? of(BuildContext context){
return context.dependOnInheritedWidgetOfExactType<${1:name}>();
}
}
@override
bool updateShouldNotify(${1:Name} oldWidget){
return ${2:true};
}
endsnippet
snippet mounted "Wheter this state object is currently in a tree" b
@override
bool get mounted{
${0:}
}
endsnippet
snippet snk "A sink is the input of a stream" b
Sink<${1:type}> get ${2:name} => _${2:name}Controller.sink;
final _${2:name}Controller = StreamController<${1:type}>();
endsnippet
snippet stm "A source of asynchronous dada events. A stream can be any data type <T>" b
Stream<${1:type}> get ${2:name} => _${2:name}Controller.stream;
final _${2:name}Controller = StreamController<${1:type}>();
endsnippet
snippet subj "A behaviorSubject is also a broadcast StreamContoller which returns an observable rather than a Stream" b
Stream<${1:type}> get ${2:name} => _${2:name}Subject.stream;
final _${2:name}Subject = BehaviorSubjec<${1:type}>;
endsnippet
snippet toStr "Returnr a string representation of this object." b
@override
String toString(){
return ${1:toString};
}
endsnippet
snippet debugP "Prints a message to the console, which you can access using the flutter tool's logs commnad" b
debugPrint(${1:statement});
endsnippet
snippet importDefault "Import a default flutter import" b
import '${1:}';
endsnippet
snippet mateapp "A default Material App template" b
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(
title: ${1:Title},
home: ${2:Home},
theme: ThemeData(),
)
);
endsnippet
snippet cupeapp "Crater a default Cuppertino app template" b
import 'package:flutter/cupertino.dart';
void main()=> runApp(CupertinoApp(
title: ${1:title},
home: CupertinoScaffold(
${2:},
),
)
);
endsnippet
snippet tweenAnimationBuilder "Widget builder that animeates a property of a widget to a target value whenecer the target value changes" b
TweenAnimationBuilder(
duration: ${1:const Duration(),},
tween: ${2:Tween(),},
builder: (BuildContext context, ${3:dynamic} value, Widget? child){
return ${4:Container();};
},
),
endsnippet
snippet valueListenableBuilder "The text is exceeded" b
ValueListenableBuilder(
valueListenable: ${1: null},
builder:(BuildContext context, ${2:dynamic} value, Widget? child){
return ${3:Container};
},
),
endsnippet
snippet f-test "Create a test function" b
test(
\ ${1:test description} \
(){},
);
endsnippet
snippet widgetTest "Create a testWidget function haha" b
testWidget(
\ ${1: test description} \
(WidgetTester tester) async {},
);
endsnippet