Giter Site home page Giter Site logo

xamantra / momentum Goto Github PK

View Code? Open in Web Editor NEW
117.0 5.0 14.0 1.46 MB

MVC pattern for flutter. Works as state management, dependency injection and service locator.

Home Page: https://www.xamantra.dev/momentum

License: BSD 3-Clause "New" or "Revised" License

Dart 100.00%
flutter state-management dependency-injection package momentum mvc mvc-pattern flexible mvc-architecture

momentum's People

Contributors

drago-vlc avatar kovacbb avatar oliverpool avatar xamantra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

momentum's Issues

Named Routing

Flutter for web matches the names of the routes to the URL in the browser.
I didn't find any information how to use named routes in Momentum. Does it support it?

How to handle state management for each model item in a collection?

I'm unfamiliar with flutter/dart/widgets so bear with me if this is a silly question.

I have a Book model, which contains a collection of Page models.
The Book controller has all the logic for adding/deleting pages and so on.

I want the Page controller to have the logic for adding/removing text in the page. I'm not sure how to achieve this with Momentum. I can write the Page controller, but it has a 1 to 1 relationship with a single Page object right?

Basically I want the user to be able to select a page, and then edit that page. In the past when I used a MVVM architecture in TornadoFX I could simply change the ViewModels item field to whatever Page Model the user clicked on and then when the ViewModel changed, it updated the model behind the scenes.

Can I achieve something similar with Momentum, or will I be fighting against its convention?

Controller can not call bootstrap & bootstrap async after reset

Hi,
I met a problem in my app flow that when I logout the app, I call Momentum.resetAll(context). And then I login again. But the controller never re-call bootstrap & bootstrap async then it has not fetched new data.
How should I do in this situation?

I try to resolve this by reset _booted & _bootedAsync in this function. Is it ok?

void reset({bool clearHistory}) {
_checkInitImplementation();
if (clearHistory ?? false) {
_momentumModelHistory.clear();
_currentActiveModel = init();
_momentumModelHistory.add(_currentActiveModel);
_initialMomentumModel = _momentumModelHistory[0];
_latestMomentumModel = _momentumModelHistory[0];
_nextModel = null;
_prevModel = null;
_setMomentum(null, backward: true);
} else {
_currentActiveModel = init();
_setMomentum(init());
}
if (_momentumLogging) {
print(_formatMomentumLog('[$this] has been reset.'));
}
}

Does calling init() do anything?

Hi,
I tried calling init() thinking that it would reset the values to the initial values but it seems like it doesn't do anything, I have to rely on reset() instead. Is this correct?

Is this package production ready?

Hello,
As the title says I am wondering if you'd vouch for this package to be production ready.
I have to say that after reading through the documentation I am really impressed with your work and Momentum seems to be what I was looking for , for a long time. However I do not really like using the dev branch inside a serious project(the problem with Route name ambiguity) and the fixed version doesn't seem to be on pub yet.
Thank you for an answer and keep up the great work !

Write a medium article

Don't forget to insult other state management systems while ignoring any valid critic! /s

Model.fromJson is not a valid override of MomentumModel.fromJson

I updated my flutter as shown on the screenshot, and on updating the project to null safety features i see this error on every momentum model => 'ArticlesModel.fromJson' ('ArticlesModel Function(Map<String, dynamic>)') isn't a valid override of 'MomentumModel.fromJson' ('MomentumModel<MomentumController>? Function(Map<String, dynamic>?)').

Screenshot (298)

Screenshot (297)

Async documentation is kind of confusing

I was reading it and it said future builder might not be needed, but no where does it show how you're executing loadingSomeData. I checked the listify example and the source code and there's no magic being applied here.

Is there something missing from the documentation here: https://xamdev.gq/momentum/#/asynchronous

My guess was the call was meant to be inside of a initMomentumState before the builder was ran. But you forgot to create the example code for that.

Feature Request: Add DI between services

In my current project, I have a StorageService, DownloadService and an APIService.
More often than not, whatever is downloaded needs to be stored in the database and the API needs to be called to get the bucket URL for downloading the file.

Would it make sense to be able to access services using getService inside a MomentumService?
Or should I stick to injecting them through the bootStrap of a non-lazy controller?

Error: The method 'inheritFromWidgetOfExactType'

Hi, I was working on a project that was working before but then I decided to switch to master channel and back to beta. Now it isn't working when I try to run and debug on vscode of use flutter run -d chrome. This is the error I'm getting:

"/C:/flutter/.pub-cache/hosted/pub.dartlang.org/momentum-1.3.3/lib/src/momentum_base.dart:1559:21: Error: The method 'inheritFromWidgetOfExactType' isn't defined for the class 'BuildContext'.

  • 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/C:/flutter/packages/flutter/lib/src/widgets/framework.dart').
    Try correcting the name to the name of an existing method, or defining a method named 'inheritFromWidgetOfExactType'.
    return (context.inheritFromWidgetOfExactType(Momentum) as Momentum);
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Failed to compile application."

I'm using flutter web by the way.

Add support for RouteSettings in the Router & how do we deal w/ screen constructors w/ Routers?

Currently there's two ways you would probably want to pass data to a route. Say you have a new todo item that belongs to a category. Maybe you want to create a separate page screen for adding that todo item to said category. Instead of redirecting to an empty constructor you might want to initialize that constructor by passing the category id, but a category isn't required so maybe sometimes you won't add a todo item to a parent id at all and no constructor initialization is needed. The other way would be just passing basic data to the build method using RouteSettings when traveling to another page for instance displaying the results from the previous page's calculations.

Router.goto(context, AddItemScreen) is the default way to do this with Momentum which is great, simple love it. Maybe there's optional named arguments though in that screen class that takes a value. Currently there's no way to pass data to that. Not sure what the cleanest way to do it would be, but I do know Function.apply is a thing, not sure how you would do it for constructors though.

void main() {
  var hmm = Function.apply(Test.init, ["hey"]);
  print(hmm.data);
}


class Test {
  String data;
  Test({this.data});
  static Test init(String data) {
    return Test(data: data);
  }
}

As for RouteSettings, that seems like that could just be passed to the MaterialPageRoute that gets created. I wouldn't mind submitting a PR for RouteSettings support later this week if you don't get to it, but the other constructor stuff is interesting and would be a lovely feature.

Feature Request: Selective persistance

Currently, persistSave gets called each time model.update is triggered. This forces all models to be persisted, regardless of which model it is.

There are two cases why we would need selective persistence:

  • One, I have an AuthModel and a AppModel. I don't really want to persist AuthModel because I run validation checks when the app starts and make a request to the server. But I definitely want to persist the AppModel each time model.update is called.

  • Second, I use Hive to store my AppModel because it's pretty complex and FlutterSecureStorage for AuthModel for it's added security in iOS. In the current version of momentum, I have my hands tied regarding which persistence mechanism I can use, as I don't know which model I'm persisting in the RunTime

So I suggest that passing the type of MomentumModel along with the persistSave call, so we can better tailor it to the need of the application.

bootstrapAsync doesn't affect the appLoader

As per the documentation, the appLoader widget should be shown till the bootstrapAsync method of a controller finishes executing. But, it does not seem to work.

The following is my code snippet from main.dart:

    Momentum(
      controllers: <MomentumController<dynamic>>[
        AuthController()..config(lazy: false)
      ],
      services: [StorageService()],
      appLoader: MaterialApp(
        home: Scaffold(
          backgroundColor: Colors.black,
          body: Center(
            child: CircularProgressIndicator(),
          ),
        ),
      ),
      child: MaterialApp(
        debugShowCheckedModeBanner: false,
        theme: ThemeData(
          accentColor: Colors.indigoAccent,
          primaryColor: Colors.green,
          textTheme: GoogleFonts.montserratTextTheme(),
        ),
        home: Root(),
      ),
    ),

The following is the snippet from the controller.dart file

@override
  Future<void> bootstrapAsync() async {
    await getService<StorageService>().init();
    final token = getService<StorageService>().getAuthToken();
    if (token == null) {
      model.update(
        token: null,
        isAuthenticated: false,
      );
    } else {
      model.update(
        token: token,
        isAuthenticated: true,
      );
    }
    await Future.delayed(const Duration(seconds: 10));
    return super.bootstrapAsync();
  }

I expected a 10 second circular progress bar. But it see the progress bar for about 200 ms.

How access to model outside controller and view?

Hello, first of all I would like to thank your work for this incredible library, but I have a question.

How a model variable can be accessed outside of the controller as from a view, that is, in a normal class.

for example, I have a class for network request,

@freezed
class UserClient extends BaseClientGenerator with _$UserClient {
  const UserClient._() : super();

  factory UserClient.login(UserModel user) = _Login;
  factory UserClient.get() = _Get;

  @override
  String get baseURL => "http://192.168.0.11:7000/api/v1/user/";

  @override
  Map<String, dynamic> get header {
    final SessionModel theme = new SessionModel(); // here
    Map<String, dynamic> headers =  {"Content-Type": "application/json"};
    maybeWhen<Map<String, dynamic>>(
      login: (_) => headers,
      orElse: () => headers,
    );
    return headers;
  }

The objective is to obtain the value to concatenate in the headers

I need to get current JWT value from my session model...

enum SessionAction {
  none,
  success,
  error,
}

class SessionEvent {
  final SessionAction action;
  final String? message;

  SessionEvent({
    required this.action,
    this.message,
  });
}

class SessionModel extends MomentumModel<SessionController>
    with EquatableMixin {
  SessionModel(
    SessionController controller, {
    required this.token,
    required this.name,
    required this.lastName,
    required this.password,
    required this.email,
  }) : super(controller);

  final String token;
  final String name;
  final String lastName;
  final String password;
  final String? email;

  @override
  void update({
    String? token,
    String? name,
    String? lastName,
    String? password,
    String? email,
  }) {
    SessionModel(controller,
            token: token ?? this.token,
            name: name ?? this.name,
            lastName: lastName ?? this.lastName,
            password: password ?? this.password,
            email: email ?? this.email)
        .updateMomentum();
  }

  @override
  Map<String, dynamic> toJson() {
    return {
      'token': token,
      'name': name,
      'lastName': lastName,
      'password': password,
      'email': email,
    };
  }

  @override
  SessionModel? fromJson(Map<String, dynamic>? json) {
    if (json == null) return null;

    return SessionModel(
      controller,
      token: json['token'],
      name: json['name'],
      lastName: json['lastName'],
      password: json['password'],
      email: json['email'],
    );
  }

  @override
  List<Object?> get props => [token, name, lastName, password, email];
}

How can I read those values in the cleanest way possible, thank you very much

Make controllers in momentum builder optional

image

It can already accept an empty list and nothing happens when you don't pass anything but the IDE complains; Why not just make it optional because sometimes you might instantiate the whole controller in a momentum state object which makes the call to snapshot almost unnecessary at times. I get there's many ways you could set it up, I just notice the way I've been working with momentum I do a lot of initiating of controllers before using them and access what I need w/out actually using snapshot (or making direct calls to model) as much as I would or should.

I have an example: I have a screen which has only one purpose and that's to add an item to the database, complain on any errors and then redirect to another route. Since it's using TextFields + TextEditingControllers it's not displaying much directly from the model which doesn't warrant a direct call to the model itself from outside of the controller.

Shouldn't be a breaking change either and probably a two second change since you already handle null controller values after checking the source.

Add a way (and or option) to allow lazy loading of controller's bootstrapping when called via Momentum.controller<T>()

That was kind of a tough title, so let me expand on that.

I've notice (working on my 2nd project now) that the way I've been using momentum I don't always need to use snapshot data from momentum builder and I don't always need to disable lazy loading of controllers in the momentum configuration. Sometimes I have a screen that just uses a single method from a controller w/out accessing the model data at all and since that's the main usage of momentum builder (outside of managing the state), which means I don't necessarily need to access snapshot when I setup my controllers in the InitMomentumState method 9 times out of 10.

Suggestion

Allow a setting or just outright default functionality for when we call Momentum.controller<T>(context) to trigger bootstrap the first time its called when lazy is set to true. So you don't have to pass the controller to controllers property of the momentum builder in the event of not needing to use snapshot for whatever reason.

Question regarding persistance

Was reading the docs, does the Router require persistSave to work? Also is persistSave tied up to models as well? If yes to both of these questions, my last question would be what if I didn't want to use persistSave with model data is there a way to only have this work with the Router only?

Improve code doc

Unfortunately, it isn't totally clear what the parameters do.

It would be great to explain it better in the code docs.

  /// Configure your app with [Momentum] root widget.
  ///
  /// The parameter `child` is not required for *unit testing*.
  factory Momentum({
    Key? key,
    Future<void> Function()? initializer,
    Widget? child,
    Widget? appLoader,
    required List<MomentumController> controllers,
    List<MomentumService>? services,
    ResetAll? onResetAll,
    bool? disabledPersistentState,
    bool? enableLogging,
    int? maxTimeTravelSteps,
    bool? lazy,
    int? minimumBootstrapTime,
    BootstrapStrategy? strategy,
    PersistSaver? persistSave,
    PersistGet? persistGet,
    String? testSessionName,
    void Function()? restartCallback,
  })

Routing interceptor - initial page based on authorization logic

Hi!
Is there any way to handle some kind of "guard" for routing? How to handle token expiration? Right now the only solution is to check whether the token has expired on each page? Should I be able to override MomentumRouter.getActivePage(context), to apply my own logic for ActivePage?

Dependency injection is flawed.

Having dependency injection would be good for creating mock controllers or hiding the implementation details, but as it stands, this can't be done. Momentum uses Object.runtimeType, which does not account for Mixing, Implementing or Extending classes, and is unsafe on dart2js in some scenarios. The functions that use Object.runtimeType should be refactored to use 'foo is T', and the places that should be refactored are Momentum._validateControllers, Momentum._getControllerOfType. Additionally, not related to the DI, Router._goto should also be refactored for the same reason.

Global lazy strategy not being applied to controllers

Here's an example of an app I have.

Momentum(
  disabledPersistentState: true,
  strategy: BootstrapStrategy.lazyFirstCall,
  controllers: [
    ItemIndexController()..config(lazy: false),
    ItemManageController(),
    LabelManageController(),
    LabelIndexController()..config(lazy: false),
    SettingsController(),
  ],
// ... snipped ...
)

In theory this should work fine and any time i call the LabelManageController for the first time it should initialize one of my services. Thing is, that doesn't work. So I had to manually set it in the config() for it to work like so:

Momentum(
  disabledPersistentState: true,
  strategy: BootstrapStrategy.lazyFirstCall,
  controllers: [
    ItemIndexController()..config(lazy: false),
    ItemManageController(),
    LabelManageController()
      ..config(strategy: BootstrapStrategy.lazyFirstCall),
    LabelIndexController()..config(lazy: false),
    SettingsController(),
  ],
// ... snipped ...
)

Exception has occurred. _AssertionError (Failed assertion: boolean expression must not be null)

On version 1.2.7 i was having this issue trying to use the model.update method. It would throw an exception on the updateMomentum() method in my controller. Then i upgraded to 1.3.0, and the exception was now thrown from the momentum_base.dart file.
Then i referenced issue number two above and exported the ref: dev-1.3.1 from the git repo, the exception now is being thrown, as shown in the screenshot attached, in the _persistModel method. I have checked all my code, and went through the documentation, cant find any reference to it. Maybe there is something wrong in my code. Kindly help and offer a solution if any please.

Screenshot (14) = The exception
Screenshot (15) => the model
Screenshot (16) => where I'm calling the update model method
Screenshot (17) => init() method.

Boolean expression must not be null

When I have more than one config(lazy: false) controller set (and this has only happened when I have two controllers w/ custom config calls. I get this error:

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following assertion was thrown building FutureBuilder<bool>(dirty, state: _FutureBuilderState<bool>#33b89):
Failed assertion: boolean expression must not be null

The relevant error-causing widget was: 
  Momentum file:///Z:/Programming/Flutter/mywir/lib/main.dart:17:5
When the exception was thrown, this was the stack: 
#0      _MomentumRootState.build.<anonymous closure> (package:momentum/src/momentum_base.dart:1055:22)
#1      _FutureBuilderState.build (package:flutter/src/widgets/async.dart:732:55)
#2      StatefulElement.build (package:flutter/src/widgets/framework.dart:4619:28)
#3      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4502:15)
#4      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4675:11)

Going to see if I can create a reproduction of this error because I'm not doing anything crazy, I just wanted to make both controllers unlazy

    Momentum(
      disabledPersistentState: true,
      controllers: [
        ItemIndexController()..config(lazy: false),
        ItemManageController(),
        LabelManageController(),
        LabelIndexController()..config(lazy: false),
      ],

If I remove config lazy on the first result no problem app loads normally. albeit my bootstrap isn't set until I call that controller.

MomentumRouter.resetWithContext and Momentum.restart not working

I updated my flutter sdk to sdk: ">=2.15.1 <3.0.0", and updated the whole app to be null-safe, but that resulted in the MomentumRouter.resetWithContext and Momentum.restart not working. The issue after countless tries seems to be the .resetWithContext function, because upon calling those functions to reset initial page say upon login, or wanting to do Navigate and Replace, the app clearly restarts, but goes back to app initial or whatever was your welcome or first page thereby not persisting login.

I have resorted to use MomentumRouter.goto for the time being just so the app can login since MomentumRouter.resetWithContext and Momentum.restart won't allow navigation to new page from Login Page, but the issue of persisting login is still an issue. Before the sdk update they were working as expected. As the video shows the last try that gets in the app uses MomentumRouter.goto, the other first tries was using MomentumRouter.resetWithContext and Momentum.restart.

Screenshot (308)

Android.Emulator.-.Pixel_4_XL_API_30_5554.2022-02-06.mp4

Is it possible to persist data on one single model alone?

I've gone through the example app and the documentation as well. It does tell us how to persist all the state in the app but I couldn't figure out how to make a single model persist while the other state gets cleared on a reboot.

Any help would be much appreciated.

Update: Found the solution. Adding JSON serialization to a model will make it persist. Models without toJson and fromJson will not persist.

System back button and Router

hello, i have been trying out Momentum and its going on well so far (its now my default state management plugin 🙂). However on using the built-in Momentum Router option i cant seem to make the system back button to work the same way as Router.pop(..)
I have Router.pop(..) on the AppBar for navigating to the previous page and its working just fine when i press it. But when i use the phone system back button the app closes instead of acting like Router.pop(..).
Is there something im doing wrong

rebuild is not triggered after updating the model, After Hot Restart

This is a very absurd issue. The library works as expected first time, after building the application.

But after I hot-restart the app, .updateMomentum doesn't seem to work.
This is because, after the hot-restart, the logger says that there are no active listeners.

It's a very simple application

app.controller.dart

class AppController extends MomentumController<AppModel> {
  @override
  AppModel init() {
    return AppModel(this);
  }

  @override
  Future<void> bootstrapAsync() async {
    return super.bootstrapAsync();
  }

  /// Add a new project to the project
  void addProject(Project project) {
    model.update(appProjects: model.appProjects..add(project));
  }
}

app.model.dart

class AppModel extends MomentumModel<AppController> {
  final List<Project> _appProjects;

  /// Getter for all the [_appProjects]
  List<Project> get appProjects => _appProjects.reversed.toList();

  /// Default constructor
  AppModel(AppController controller,
      {List<Project> appProjects = const <Project>[]})
      : _appProjects = []..addAll(appProjects.toList()),
        super(controller);

  @override
  void update({List<Project> appProjects = const []}) {
    AppModel(controller, appProjects: []..addAll(appProjects)).updateMomentum();
  }
}

main.dart

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    SizeUtil().init(context);
    Dimens().init(context);
    return Momentum(
      controllers: <MomentumController<dynamic>>[
        AppController()..config(lazy: false),
        ProjectDetailController()
      ],
      services: [],
      enableLogging: true,
      child: MaterialApp(
        debugShowCheckedModeBanner: false,
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.teal,
          visualDensity: VisualDensity.adaptivePlatformDensity,
        ),
        home: HomePage(),
      ),
    );
  }
}

This is how I update the state. The addProject method

  void addProject() {
    Momentum.controller<AppController>(context).addProject(defaultProject);
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: FloatingActionButton.extended(
        label: Text('NEW VIDEO LESSON'),
        icon: Icon(Icons.add),
        onPressed: addProject,
      ),
      body: MomentumBuilder(
        controllers: [AppController],
        builder: (context, snapshot) {
          final model = snapshot<AppModel>();
          return ListView(
            children: <Widget>[
              for (final project in model.appProjects)
                Card(
                  elevation: 4,
                  child: ListTile(
                    title: Text('${project.projectName}'),
                    subtitle: Text('${project.videos.length} Video(s)'),
                    trailing: Icon(Icons.video_call),
                  ),
                ),
                ...
                ...
                ... 
      ),
    );

After a COMPLETE rebuild/restart, and I hit the "Add Button"

I/flutter (21486): [Momentum -> 'AppController'] the model "AppModel" has been updated, listeners => ACTIVE: 1 (notified), INACTIVE: 0 (ignored)

After a HOT RESTART, and I hit the "Add Button"

I/flutter (21486): [Momentum -> 'AppController'] the model "AppModel" has been updated, listeners => ACTIVE: 0 (notified), INACTIVE: 0 (ignored)

This is really frustrating. I really liked this architecture. Can anyone tell me what I'm doing wrong?

Model is not initialised on Testing

Here are some example of my controllers,

  PreloadController()..config(lazy: false),
  ProfileController(),

Screenshot 2020-07-31 at 6 02 14 PM
.
But on the testing documentation, it seems that the model should've been initialised.

Suggestion: A way to redirect to the previous page

So in an app I made, shameless plug, I have a situation where I can double click on an item to edit it w/out actually going to the view item entry page. The other way to update the entry is by going to the view entry (to see the description/title/date info formatted) then hitting the edit button. Well when I edit and I was on the view item page previously I'd want to redirect them there. But if I came from the index list of all the items I'd want to redirect them back to that page.

Now there's ways to do this already, even by using the new router param feature we suggested a few versions ago to pass parameter data (I'm probably going to do this for now), or just using the controller/model data and setting the page they came from whether its the view list or main list page.

This could be simplified since I'm sure you already keep track of the current route information by calling something to Router.gotoPrev() or Router.prev()

More on Time Travel (undo/redo)

Hello @xamantra i have looked at the listify example and the documentation, it looks like time-travel works best with TextFields is there a way it can work for other models

Imagine a scenario:
I add my todos which are in a list just like listify example, but i want to do undo and redo on my todos when i delete a particular todo in my list of todos and not on text fields like what the example listify is doing
Is this possible with momentum's time travel?

Error handling in MomentumBuilder

When using a Stream, we can add an error via its .addError(error) function. Then any StreamBuilder that is listening to it could get the error object via the AsyncSnapshot object.
That allows us to return a different widget to the builder function when any error occurs.

Is there something similar that we can do with MomentumBuilder?

I know we can send an event and just show a SnackBar instead. But in some cases we want to show an error widget to the screen itself.

Any thoughts?

Thanks!

Add try..catch while initing controllers and services

Any exception that gets thrown inside MomentumRoot's _init() results in:

The following assertion was thrown     building FutureBuilder<bool>(dirty, state:_FutureBuilderState<bool>#9e6fe):
  8 Failed assertion: boolean expression must not be null

The dev can never understand which one of the init methods threw which exception. This especially becomes painful when you blind code multiple controllers and then run the app to see if they are working as you envisioned.

Adding a try...catch inside _init() and then logging the stack-trace would probably save a bunch of time for devs who do the above.

New Storage Example

Hi @xamantra
Thanks for the list-example.
It would be interesting to see some storage example, maybe together with already existing rest api example.
I'm wondering how could we chose storage provider, other then shared_preferences.
Would sqlite be possible with current implementation, as it's not key-value?
Cheers.

Configure Router persistence

Hello @xamantra i know navigation persistence is a cool feature for momentum but i came across this problem
Say i have pageB() that has its controller with no persistence, and it gets some of the data it needs via RouterParam from pageA(), e.g when i press a product and i navigate to product-details-page
When i add the persistGet and persistSave, and i close the app while at pageB(), and open again..Based on persistence i will be back at pageB() but i have lost the data (passed via RouterParam) and i get null errors sometimes

Am i doing it wrong or there should be an option, to optionally enable Navigation persistence or not

Router for not persitant navigation

Hi,
Use Router in service param in Momentum bring confusion with standard Router Navigation Name in Flutter.
Because Router require persistSave and persistGet param and I must manage the persistance...

So if I want use Navigation without persistance, I've 2 options:

  • Use classic Navigator in widget (example: called in onPressed method)

If I want extract logic in Controller component

  • So, create a third component: MomentumState and use classic Navigator instead Router in .addListener or .listen (with .sendEvent) method for have a context ?

Thank you for your response :)

Flutter Web - [Momentum]: Failed to initialize your app.

Momentum is throwing me this error when I do flutter run -d chrome.

======== Exception caught by widgets library =======================================================
The following MomentumError was thrown building _MomentumRoot(dirty, dependencies: [Momentum], state: _MomentumRootState#6afe7):
[Momentum]: Failed to initialize your app. Check the above stacktrace for details.

The relevant error-causing widget was: 
  _MomentumRoot file:///C:/tools/flutter/.pub-cache/hosted/pub.dartlang.org/momentum-2.0.1/lib/src/momentum_base.dart:1368:14
When the exception was thrown, this was the stack: 
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 236:49  throw_
packages/momentum/src/momentum_base.dart 1279:7                                                                            build
packages/flutter/src/widgets/framework.dart 4612:27                                                                        build
packages/flutter/src/widgets/framework.dart 4495:15                                                                        performRebuild
packages/flutter/src/widgets/framework.dart 4667:11                                                                        performRebuild
...
====================================================================================================

Flutter doctor

[√] Flutter (Channel stable, 2.0.4, on Microsoft Windows [Versión 10.0.19042.867], locale es-ES)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[√] Chrome - develop for the web
[√] Android Studio (version 4.1.0)
[√] IntelliJ IDEA Community Edition (version 2020.3)
[√] VS Code (version 1.55.1)
[√] Connected device (2 available)

! Doctor found issues in 1 category.

flutter --version

Flutter 2.0.4 • channel stable • https://github.com/flutter/flutter.git
Framework • revision b1395592de (8 days ago) • 2021-04-01 14:25:01 -0700
Engine • revision 2dce47073a
Tools • Dart 2.12.2

Error on new Flutter

momentum-1.3.1/lib/src/momentum_base.dart:99:18: Error: 'Router' is imported from both 'package:flutter/src/widgets/router.dart' and 'package:momentum/src/momentum_router.dart'.
var result = Router.getParam(_mRootContext);

momentum_base.dart:6:1: Error: 'Router' is imported from both 'package:flutter/src/widgets/router.dart' and 'package:momentum/src/momentum_router.dart'.
import '../momentum.dart';

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.