axmvvm 0.3.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

AxMVVM #

Affixal MVVM - Clean and easy to use MVVM Architecture for Flutter

  • ViewModel base class.
  • ViewModel-First navigation.
  • Dependency Injecton with IoC Container.
  • Command Design Pattern.
  • Publish/Subscribe Design Pattern.
  • Localization Service.
  • Navigation Service.
  • Data Binding & Value Converter
  • Base class for views & widgets.

@ Inspired by Kevin Ford's fmvvm architecture - https://github.com/Bowman74/fmvvm

[0.3.4] #

  • Update documentation.

  • TODO:

    • Unit tests.
    • Create better example.

[0.3.3] #

  • Format documents.
  • Remove unused imports.

[0.3.2] #

  • Change some AxAPP method names.
  • Update documenttion.

[0.3.1] #

  • Add layout information to state views and widgets

[0.3.0] #

  • Add resumed() and paused() methods to base viewmodel.
  • Update documentation.

[0.2.3] #

  • Change App Setup.

[0.2.2] #

  • Now its possible to create lazySingletons.
  • Change how back button handle event works.
  • Added view events when app goes background and foregorund.
  • Update documentation.

[0.2.1] #

  • Refactor closing viewModel.

[0.2.0] #

  • Fix async navigation.
  • Fix navigate back methods.

[0.1.3] #

  • Fix createViewModelForBottomNavigation and createViewModelForInitialView methods.

[0.1.2] #

  • Refactor dependency registration method.

[0.1.1] #

  • Update package description.

[0.1.0] #

  • First Affixal MVVM release.

example/lib/main.dart

import 'package:axmvvm/models/models.dart';
import 'package:flutter/material.dart';

import 'package:axmvvm/axmvvm.dart';
import 'package:axmvvm/services/services.dart';
import 'package:axmvvm/bindings/bindings.dart';

void main() => runApp(MyApp());

class MyApp extends AxApp {
  @override
  AppConfiguration appConfiguraton() => AppConfiguration('AxMVVM');

  @override
  void registerDependencies(AxContainer container) {
    container.registerLazySingleton<IWebLoginService>(() => WebLoginService());
    container.registerTransient<MainViewModel>(() => MainViewModel(container.getInstance<IWebLoginService>()));
    container.registerTransient<TestViewModel>(() => TestViewModel(container.getInstance<IWebLoginService>()));
  }

  @override
  Widget initialView(INavigationService navigationService) {
    return MainView(navigationService.createViewModelForInitialView<MainViewModel>());
  }

  @override
  Route<dynamic> routePlanner(RouteSettings settings) {
    return createRoute(settings, TestView(settings.arguments));
  }
}

class MainView extends AxStatelessView<MainViewModel> {
  MainView(ViewModel viewModel) : super(viewModel);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('AxMVVM'),
      ),
      body: InkWell(
        onTap: () => viewModel.loginCommand.execute(parameter: 'AxMVVM'),
        child: const Text('Hello!'),
      )
    );
  }
}

class MainViewModel extends ViewModel {
  final IWebLoginService _loginService;
  MainViewModel(this._loginService);

  AxCommand<String> _loginCommand;

  AxCommand<String> get loginCommand => _loginCommand ??= AxCommand<String>(
    actionParam: ({String parameter}) => verifyLogin(parameter), canExecute: checkLoading);

  Future<void> verifyLogin(String name) async {
    _loginService.login(name);
    await ViewModel.navigationService.navigateAsync<TestViewModel>();
    print('back');
  }

  bool checkLoading() => !isBusy;
}

class TestView extends AxStatefulView<TestViewModel> {
  TestView(ViewModel viewModel) : super(viewModel);

  @override
  State<StatefulWidget> createState() => TestViewState(viewModel);

}

class TestViewState extends AxStateView<TestView, TestViewModel> {
  TestViewState(ViewModel viewModel) : super(viewModel);
  @override
  Widget build(BuildContext context) {
    return handleBackButton(
      view: Scaffold(
        appBar: AppBar(
          title: const Text('AxMVVM'),
        ),
        body: InkWell(
            onTap: () => viewModel.loginCommand.execute(parameter: 'AxMVVM'),
            child: const Text('Hello 1!'),
      ))
    );
  }
}

class TestViewModel extends ViewModel {
  final IWebLoginService _loginService;
  TestViewModel(this._loginService);

  AxCommand<String> _loginCommand;
  AxCommand<String> get loginCommand => _loginCommand ??= AxCommand<String>(
    actionParam: ({String parameter}) => verifyLogin(parameter), canExecute: checkLoading);

  Future<void> verifyLogin(String name) async {
    _loginService.login(name);
    final ObjectTest test = await ViewModel.navigationService.navigateForResultAsync<ObjectTest, TestViewModel>();
    if(test != null)
      print(test.name);
  }
  
  // @override
  // Future<void> close() async {
  //   ViewModel.navigationService.navigateBackWithResultAsync<ObjectTest, ViewModel>(ObjectTest('TEst Workingdawda!!!'), this);
  // }

  bool checkLoading() => !isBusy;
}

abstract class IWebLoginService {
  void login(String name);
}

class WebLoginService implements IWebLoginService{
  @override
  void login(String name) {
   print(name);
  }
}

class ObjectTest {
  final String name;
  ObjectTest(this.name);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  axmvvm: ^0.3.4

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:axmvvm/axmvvm.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

We analyzed this package on Apr 6, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Fix lib/bindings/axbindwidget.dart. (-0.50 points)

Analysis of lib/bindings/axbindwidget.dart reported 1 hint:

line 19 col 51: 'ancestorWidgetOfExactType' is deprecated and shouldn't be used. Use findAncestorWidgetOfExactType instead. This feature was deprecated after v1.12.1..

Format lib/axapp.dart.

Run flutter format to format lib/axapp.dart.

Format lib/axcontainer.dart.

Run flutter format to format lib/axcontainer.dart.

Fix additional 32 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/axcore.dart (Run flutter format to format lib/axcore.dart.)
  • lib/axdependency.dart (Run flutter format to format lib/axdependency.dart.)
  • lib/axmvvm.dart (Run flutter format to format lib/axmvvm.dart.)
  • lib/bindings/base_views/axstatefulview.dart (Run flutter format to format lib/bindings/base_views/axstatefulview.dart.)
  • lib/bindings/base_views/axstatelessview.dart (Run flutter format to format lib/bindings/base_views/axstatelessview.dart.)
  • lib/bindings/base_views/axstateview.dart (Run flutter format to format lib/bindings/base_views/axstateview.dart.)
  • lib/bindings/base_widgets/axstatefulwidget.dart (Run flutter format to format lib/bindings/base_widgets/axstatefulwidget.dart.)
  • lib/bindings/base_widgets/axstatelesswidget.dart (Run flutter format to format lib/bindings/base_widgets/axstatelesswidget.dart.)
  • lib/bindings/base_widgets/axstatewidget.dart (Run flutter format to format lib/bindings/base_widgets/axstatewidget.dart.)
  • lib/bindings/bind.dart (Run flutter format to format lib/bindings/bind.dart.)
  • lib/bindings/bindablebase.dart (Run flutter format to format lib/bindings/bindablebase.dart.)
  • lib/bindings/bindings.dart (Run flutter format to format lib/bindings/bindings.dart.)
  • lib/bindings/fielddata.dart (Run flutter format to format lib/bindings/fielddata.dart.)
  • lib/bindings/fielddata_manager.dart (Run flutter format to format lib/bindings/fielddata_manager.dart.)
  • lib/bindings/notificationlist.dart (Run flutter format to format lib/bindings/notificationlist.dart.)
  • lib/bindings/propertyinfo.dart (Run flutter format to format lib/bindings/propertyinfo.dart.)
  • lib/bindings/viewmodel.dart (Run flutter format to format lib/bindings/viewmodel.dart.)
  • lib/models/appconfiguration.dart (Run flutter format to format lib/models/appconfiguration.dart.)
  • lib/models/layout_information.dart (Run flutter format to format lib/models/layout_information.dart.)
  • lib/models/localization.dart (Run flutter format to format lib/models/localization.dart.)
  • lib/models/location.dart (Run flutter format to format lib/models/location.dart.)
  • lib/models/messenger.dart (Run flutter format to format lib/models/messenger.dart.)
  • lib/models/models.dart (Run flutter format to format lib/models/models.dart.)
  • lib/models/subscription.dart (Run flutter format to format lib/models/subscription.dart.)
  • lib/services/implementations/localization_service.dart (Run flutter format to format lib/services/implementations/localization_service.dart.)
  • lib/services/implementations/message_service.dart (Run flutter format to format lib/services/implementations/message_service.dart.)
  • lib/services/implementations/navigation_service.dart (Run flutter format to format lib/services/implementations/navigation_service.dart.)
  • lib/services/interfaces/ilocalization_service.dart (Run flutter format to format lib/services/interfaces/ilocalization_service.dart.)
  • lib/services/interfaces/imessage_service.dart (Run flutter format to format lib/services/interfaces/imessage_service.dart.)
  • lib/services/interfaces/inavigation_service.dart (Run flutter format to format lib/services/interfaces/inavigation_service.dart.)
  • lib/services/services.dart (Run flutter format to format lib/services/services.dart.)
  • lib/utilities.dart (Run flutter format to format lib/utilities.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
flutter_cupertino_localizations ^1.0.1 1.0.1
flutter_localizations 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
intl 0.16.0 0.16.1
meta 1.1.8
path 1.6.4
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test