Created
November 28, 2024 17:34
-
-
Save vbalagovic/258014fa3cb0aa4151cc8cb1ef99d8f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EditMovieModal extends ConsumerStatefulWidget { | |
final Movie movie; | |
const EditMovieModal({required this.movie, super.key}); | |
@override | |
ConsumerState<EditMovieModal> createState() => _EditMovieModalState(); | |
} | |
class _EditMovieModalState extends ConsumerState<EditMovieModal> { | |
final _formKey = GlobalKey<FormState>(); | |
late Movie editedMovie; | |
@override | |
void initState() { | |
super.initState(); | |
editedMovie = widget.movie; | |
// Safe state initialization | |
WidgetsBinding.instance.addPostFrameCallback((_) { | |
ref.read(editMovieProvider.notifier).setMovie(widget.movie); | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
final movieState = ref.watch(editMovieProvider); | |
return movieState.when( | |
data: (movie) => Form( | |
key: _formKey, | |
child: // Form fields... | |
), | |
loading: () => const Center(child: CircularProgressIndicator()), | |
error: (error, stack) => Center(child: Text('Error: $error')), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment