summaryrefslogtreecommitdiff
path: root/snippets/dart-flutter.snippets
blob: f51f11ca4dc4aa40e835de4d95dad79609555e85 (plain)
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
# Snippets for dart in flutter project, to use add the following to your .vimrc
# `autocmd BufRead,BufNewFile,BufEnter *.dart UltiSnipsAddFiletypes dart-flutter`
# Flutter stateless widget
snippet stless
	class $1 extends StatelessWidget {
		@override
		Widget build(BuildContext context) {
			return Container(
				$2
			);
		}
	}

# Flutter stateful widget
snippet stful
	class $1 extends StatefulWidget {
		@override
		_$1State createState() => _$1State();
	}

	class _$1State extends State<$1> {
		@override
		Widget build(BuildContext context) {
			return Container(
				$2
			);
		}
	}

# Flutter widget with AnimationController
snippet stanim
	class $1 extends StatefulWidget {
		@override
		_$1State createState() => _$1State();
	}

	class _$1State extends State<$1>
			with SingleTickerProviderStateMixin {
		AnimationController _controller;

		@override
		void initState() {
			super.initState();
			_controller = AnimationController(vsync: this);
		}

		@override
		void dispose() {
			super.dispose();
			_controller.dispose();
		}

		@override
		Widget build(BuildContext context) {
			return Container(
				$2
			);
		}
	}

# Flutter scaffold application
snippet fsa
	void main() {
		runApp(
			MaterialApp(
				title: 'Flutter Demo',
				theme: ThemeData(
					primarySwatch: Colors.blue,
				),
				debugShowCheckedModeBanner: false,
				home: const HomePage(),
			),
		);
	}

	class HomePage extends StatelessWidget {
		const HomePage({Key? key}) : super(key: key);

		@override
		Widget build(BuildContext context) {
			return Scaffold(
				appBar: AppBar(
					title: const Text('Home Page'),
				),
			);
		}
	}