Romeo Mihalcea
Romeo Mihalcea

Reputation: 10252

Flutter for web state management

I'm toying with Flutter this weekend and I like it so far. I'm going deeper into state management right now. Coming from a React background I tried implementing redux with flutter_redux but it seems that flutter_redux is not working, neither does BloC so my question is obious: has anyone managed to have a functional state manager in flutter for web?

Upvotes: 1

Views: 1347

Answers (3)

polina-c
polina-c

Reputation: 7077

While there is no state management in flutter_web, my temporary workaround is to pass state in navigation arguments.

Upvotes: 0

Romeo Mihalcea
Romeo Mihalcea

Reputation: 10252

Ok, after long hours on this thing I finally made it work...I think. What I did was forking the flutter_redux repo and changing the import references as Rémi also pointed out but that wasn't enough because I still had an error in my IDE complaining about StoreProvider with: The return type 'StoreProvider<AppState>' isn't a 'Widget', as defined by the method 'build'..

In flutter_redux you also need to edit this file (the only one in lib actually) flutter_redux/lib/flutter_redux.dart and alter the import in order to work with flutter_web: https://github.com/ciokan/flutter_redux/commit/e8a4f099925c2960cc1bd68aa193f8f38dbd01d5

My compiler is giving me thumbs up now, I still don;t have a full working redux but I suspect the hard part was done.

Upvotes: 1

R&#233;mi Rousselet
R&#233;mi Rousselet

Reputation: 277037

That's not specific to state management. There are currently no flutter packages that you can use in the web.

To solve this temporary issue, you need to fork each package you want to use, and change a few things:

  • All imports to a flutter file must be changed from import 'package:flutter/<whatever> into import 'package:flutter_web/<whatever>

  • change the pubspec.yaml

from:

dependencies:
  flutter:
    sdk: flutter

into

dependencies:
  flutter_web:
    git:
      url: https://github.com/flutter/flutter_web
      path: packages/flutter_web
  flutter_web_ui:
    git:
      url: https://github.com/flutter/flutter_web
      path: packages/flutter_web_ui

Upvotes: 2

Related Questions