I am using flutter_riverpod
package.
I want to convert ConsumerWidget
to ConsumerStatefulWidget
.
However, it took me a lot of time to do it like this:
class Widget extends ConsumerWidget {
const Widget({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
return …;
}
}
ref
)class Widget extends ConsumerWidget {
const Widget({super.key});
@override
Widget build(BuildContext context) {
return …;
}
}
ConsumerWidget
to StatelessWidget
)class Widget extends StatelessWidget {
const Widget({super.key});
@override
Widget build(BuildContext context) {
return …;
}
}
Convert to StatefulWidget
action)class Widget extends StatefulWidget {
const Widget({super.key});
@override
State<Widget> createState() => _WidgetState();
}
class _WidgetState extends State<Widget> {
@override
Widget build(BuildContext context) {
return …;
}
}
Consumer
word)class Widget extends ConsumerStatefulWidget {
const Widget({super.key});
@override
ConsumerState<Widget> createState() => _WidgetState();
}
class _WidgetState extends ConsumerState<Widget> {
@override
Widget build(BuildContext context) {
return …;
}
}
As you can see, I need to use 5 steps to do it. Is there a faster way?
Feel free to leave a comment if you need more information.
How to convert ConsumerWidget
to ConsumerStatefulWidget
more easily? I would appreciate any help. Thank you in advance!
If my ConsumerWidget
has no parameters,
ConsumerStatefulWidget
with the same name.build
method of ConsumerWidget
to a new created widget.ConsumerWidget
) Copy content of ConsumerWidget
to a new created widget. Then remove ref
from build
.ConsumerWidget
.If my ConsumerWidget
has parameters, then I'm doing the same as you, because otherwise I'll have to add a widget.
before widget variables.