riverpod_craft 0.4.0
riverpod_craft: ^0.4.0 copied to clipboard
A code generation toolkit for Riverpod state management. Better syntax and side effect solution with commands.
Counter Example #
A simple counter with @provider and @settable:
import 'package:riverpod_craft/riverpod_craft.dart';
part 'counter_provider.craft.dart';
// Generates a provider with setState() automatically.
@provider
@settable
int counter(Ref ref) => 0;
Use in a widget — access via the generated extension on WidgetRef:
class HomePage extends ConsumerWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final count = ref.counterProvider.watch();
return Scaffold(
body: Center(child: Text('$count')),
floatingActionButton: Column(
mainAxisSize: MainAxisSize.min,
children: [
FloatingActionButton(
onPressed: () => ref.counterProvider.setState(count + 1),
child: const Icon(Icons.add),
),
const SizedBox(height: 8),
FloatingActionButton(
onPressed: () => ref.counterProvider.setState(count - 1),
child: const Icon(Icons.remove),
),
],
),
);
}
}
See the full examples directory for more: counter, notes, movies_app, command_strategies, quote, and custom_dropdown.