Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to move a variable outside build?

How do I move a variable that uses a context outside of the build method so that it is created once?

class _EventListState extends State<EventList> {
  @override
  Widget build(BuildContext context) {
    final eventNotifier = EventInherited.of(context).eventNotifier;
    ...

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can use the late modifier.

class _EventListState extends State<EventList> {
  late final eventNotifier = EventInherited.of(context).eventNotifier;
  @override
  Widget build(BuildContext context) {
    ...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading