Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Riverpod snippets #1426

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion snippets/dart-flutter.snippets
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,3 @@ snippet fsa
}
}


155 changes: 155 additions & 0 deletions snippets/flutter-riverpod.snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
################################################################################
#Full credit to Robert Brunhage for creating the original snippet for Riverpod.#
#https://github.com/RobertBrunhage/flutter-riverpod-snippets #
#I just did the grunt work to bring them over to vim-snippets #
################################################################################


#Basic Riverpod Provider
snippet provider
final $1Provider = Provider<$2>((ref){
return $3;
});

#Basic Riverpod Provider with family
snippet providerFamily
final $1Provider = Provider.family<$2,$3>((ref, $4){
return $5;
});

#Future Riverpod Provider
snippet futureProvider
final $1Provider = FutureProvider<$2>((ref) async {
return $3;
});

#Future Riverpod Provider with Family
snippet futureProviderFamily
final $1Provider = FutureProvider.family<$2,$3>((ref, $4) async {
return $5;
});

#Stream Riverpod Provider
snippet streamProvider
final $1Provider = StreamProvider<$2>((ref) async* {
return $3;
});

#Stream Riverpod Provider with Family
snippet streamProviderFamily
final $1Provider = StreamProvider.family<$2,$3>((ref, $4) async* {
return $5;
});

#Provider Listenable
snippet listen
ref.listen<$1>($2,(value) {
$3
});

#Creates a StateProvider
snippet stateProvider
final $1Provider = StateProvider<$2>((ref){
return $3;
});

#Create a StateProvider with Family modifier
snippet stateProviderFamily
final $1Provider = StateProvider.family<$2,$3>((ref, $4){
return $5;
});

#Creates a StateNotifier provider
snippet stateNotifierProvider
final $1Provider = StateNotifierProvider<$2>((ref){
return $3;
});

#Create a StateNotifierProvider with Family modifier
snippet stateNotifierProviderFamily
final $1Provider = StateNotifierProvider.family<$2,$3>((ref, $4){
return $5;
});

#Create a ChangeNotifierProvider
snippet changeNotifierProvider
final $1Provider = ChangeNotifierProvider<$2>((ref) {
return $3;
});

#Create a ChangeNotifierProvider with Family modifier
snippet changeNotifierProviderFamily
final $1Provider = ChangeNotifierProvider.family<$2,$3>((ref, $4) {
return $5;
});

#Creates a class that extends StateNotifier and allows you to edit the types
snippet stateNotifier
class $1Notifier extends StateNotifier<$2> {
$1Notifier(): super($3);
$4
}

#Create Consumer
snippet consumer
Consumer(
builder: (context, ref, child){
return $1;
}
)

#Create a ConsumerStatelessWidget
snippet stlessConsumer
class $1 extends ConsumerWidget {
const $1({Key? key}) : super(key: key);

@override
Widget build(BuildContext context, WidgetRef ref) {
return Container();
}
}

#Create a ConsumerStatefulWidget
snippet stfulConsumer
class $1 extends ConsumerStatefulWidget {
const $1({Key? key}) : super(key: key);

@override
ConsumerState<ConsumerStatefulWidget> createState() => _$1State();
}

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

#Create a HookConsumerWidget
snippet stlessHookConsumer
class $1 extends HookConsumerWidget {
const $1({Key? key}) : super(key: key);

@override
Widget build(BuildContext context, WidgetRef ref){
return Container();
}
}

#Create a StatefulHooksConsumerWidget
snippet stfulHookConsumer
class $1 extends StatefulHookConsumerWidget {
const $1({Key? key}) : super(key: key);

@override
ConsumerState<ConsumerStatefulWidget> createState() => _$1State();

}

class _$1State extends ConsumerState<$1> {

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