riverpod_builder 0.2.1 copy "riverpod_builder: ^0.2.1" to clipboard
riverpod_builder: ^0.2.1 copied to clipboard

the package to use Riverpod's Provider like the ListView and PageView widgets.We believe that Flutter development can handle it easily.

Purpose #

Easy to use awesome package Riverpod for some design pattern
I created this package to use Riverpod's Provider like the ListView and PageView widgets that are implemented in the Flutter standard.We believe that someone with experience in Flutter development can handle it easily.

View (builder) #

  @override
  Widget build(BuildContext context) {
    // wrap this buider 
    return RiverpodBuilder(
      // set use provider
      provider: firstViewModelProvider,
      builder: (context, ref, vm, state, reader) {
        return Scaffold(
          appBar: AppBar(
            title: const Text('First View'),
            automaticallyImplyLeading: false,
          )
          ...

arguments #

name mean
provider riverpod provider
builder use it like a ListView or PageView
showlog setting whether to display the Log

builder property #

name mean
context means Build Context
ref means WidgetRef
vm (notifier) ref.watch(provider.notifier);
state ref.watch(provider);
reader ref.read(provider.notifier);

log #

log_image

View Model #

class FirstViewModel extends BaseViewModel<FirstViewState> {
  @override
  get instanse => const FirstViewState();

  int get count => state.count;

  // listen other provider
  SecondViewModel get secondVM =>
      widgetRef.read(secondViewModelProvider.notifier);

  @override
  void onInit() async{
    // Asynchronous processing is also possible .
    await Future.delayed(const Duration(seconds: 1));
    super.onInit();
  }

  void addCount() {
    state = state.copyWith(count: state.count + 1);
  }

  void showNextView() {
    // has context(Build Context)
    // no arguments need to be passed.
    Navigator.of(context).pushNamed("second_view");
  }

  ...

property #

name mean
context means Build Context
ref means PrividerRef
widgetRef means WidgetRef
state this state

method #

name mean
onInit call when this class init. (Asynchronous processing is also possible)
onDispose call when this class close.
refreshProvider use invalidate(refresh) other provider.

Preview #

Status of support Providers type #

※ This package requires Riverpod 2 or higher.

corresponding #

builder provider type BaseVM
RiverpodBuilder NotifierProvider BaseViewModel
KeepRiverpodBuilder AutoDisposeNotifierProvider KeepBaseViewModel

currently we offer two types of builder.
We plan to increase the types of providers supported and adapte to hooks in the near future.

supplementary information #

We know that many people use stateNotifierProvier in this case.
However, since the Riverpod developers recommend the use of NotifierProvider, we decided to be the first to respond.

Extended package #

Extending this package is very easy.
ex : The case where you want to define common Methods that you want to use in all VM...

  • In that case, create an extension class for InnerViewModel after defining other providers..
import 'package:fluttertoast/fluttertoast.dart';

extension InnerViewModelEXT on InnerViewModel {

  // OverlayLoadingView.provider = provider to manage loading

  bool get isLoading => providerRef.read(OverlayLoadingView.provider);

  // show Loading
  void showLoading() {
    providerRef.read(OverlayLoadingView.provider.notifier).show();
  }

  // hide Loading
  void hideLoading() {
    providerRef.read(OverlayLoadingView.provider.notifier).hide();
  }

  void showAlert(String message) {
    // alert method
  }

  void showToast(String message) {
    // other packages can be defined and used here as well.
    Fluttertoast.showToast(
        msg: message, toastLength: Toast.LENGTH_SHORT, timeInSecForIosWeb: 1);
  }
}


Writing Documents more detail...

2
likes
120
pub points
28%
popularity

Publisher

unverified uploader

the package to use Riverpod's Provider like the ListView and PageView widgets.We believe that Flutter development can handle it easily.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter, flutter_riverpod

More

Packages that depend on riverpod_builder