kandi background
Explore Kits

AutoDispose | Automatic bindingdisposal of RxJava streams. | Reactive Programming library

 by   uber Java Version: 2.1.1 License: Apache-2.0

 by   uber Java Version: 2.1.1 License: Apache-2.0

Download this library from

kandi X-RAY | AutoDispose Summary

AutoDispose is a Java library typically used in Programming Style, Reactive Programming applications. AutoDispose has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has medium support. You can download it from GitHub.
Automatic binding+disposal of RxJava streams.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • AutoDispose has a medium active ecosystem.
  • It has 3220 star(s) with 205 fork(s). There are 66 watchers for this library.
  • There were 2 major release(s) in the last 12 months.
  • There are 3 open issues and 170 have been closed. On average issues are closed in 66 days. There are 2 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of AutoDispose is 2.1.1
AutoDispose Support
Best in #Reactive Programming
Average in #Reactive Programming
AutoDispose Support
Best in #Reactive Programming
Average in #Reactive Programming

quality kandi Quality

  • AutoDispose has 0 bugs and 0 code smells.
AutoDispose Quality
Best in #Reactive Programming
Average in #Reactive Programming
AutoDispose Quality
Best in #Reactive Programming
Average in #Reactive Programming

securitySecurity

  • AutoDispose has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • AutoDispose code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
AutoDispose Security
Best in #Reactive Programming
Average in #Reactive Programming
AutoDispose Security
Best in #Reactive Programming
Average in #Reactive Programming

license License

  • AutoDispose is licensed under the Apache-2.0 License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
AutoDispose License
Best in #Reactive Programming
Average in #Reactive Programming
AutoDispose License
Best in #Reactive Programming
Average in #Reactive Programming

buildReuse

  • AutoDispose releases are available to install and integrate.
  • Build file is available. You can build the component from source.
  • Installation instructions are not available. Examples and code snippets are available.
  • It has 10883 lines of code, 917 functions and 152 files.
  • It has medium code complexity. Code complexity directly impacts maintainability of the code.
AutoDispose Reuse
Best in #Reactive Programming
Average in #Reactive Programming
AutoDispose Reuse
Best in #Reactive Programming
Average in #Reactive Programming
Top functions reviewed by kandi - BETA

kandi has reviewed AutoDispose and discovered the below as its top functions. This is intended to give you an instant insight into AutoDispose implemented functionality, and help decide if they suit your requirements.

  • Fixize the method invocation .
  • Resolves the scope of the lifecycle provider .
  • Attaches view to the observer .
  • Called when the subscribe is subscribed .
  • Sets onResume callback
  • Fills the back - end events .
  • Matches an AST node that is a subtype of the given class .
  • Creates a CompletableFuture for the given ScopeProvider .
  • Executes the given value if the value is non - null and terminates .
  • On check on check thread .

AutoDispose Key Features

Automatic binding+disposal of RxJava streams.

License

copy iconCopydownload iconDownload
Copyright (C) 2017 Uber Technologies

How to upgrade bluelinelabs/Conductor version 3.1.4 from version 3.0.0

copy iconCopydownload iconDownload
    fun Completable.autoDisposable(event: ControllerEvent? = null): CompletableSubscribeProxy =
    observeOn(AndroidSchedulers.mainThread())
        .autoDisposable(getScopeProvider(event))
    private val scopeProvider: ControllerScopeProvider by lazy { ControllerScopeProvider.from(this) }

    private val destroyScopeProvider: ControllerScopeProvider by lazy {
      ControllerScopeProvider.from(
        this,
        ControllerEvent.DESTROY
      )
    }
...
    private fun getScopeProvider(event: ControllerEvent?): ControllerScopeProvider =
    when (event) {
        null -> scopeProvider
        ControllerEvent.DETACH -> detachScopeProvider
        ControllerEvent.DESTROY_VIEW -> destroyViewScopeProvider
        ControllerEvent.DESTROY -> destroyScopeProvider
        else -> throw RuntimeException("Scope for event ${event.name} wasn't created")
    }
-----------------------
    fun Completable.autoDisposable(event: ControllerEvent? = null): CompletableSubscribeProxy =
    observeOn(AndroidSchedulers.mainThread())
        .autoDisposable(getScopeProvider(event))
    private val scopeProvider: ControllerScopeProvider by lazy { ControllerScopeProvider.from(this) }

    private val destroyScopeProvider: ControllerScopeProvider by lazy {
      ControllerScopeProvider.from(
        this,
        ControllerEvent.DESTROY
      )
    }
...
    private fun getScopeProvider(event: ControllerEvent?): ControllerScopeProvider =
    when (event) {
        null -> scopeProvider
        ControllerEvent.DETACH -> detachScopeProvider
        ControllerEvent.DESTROY_VIEW -> destroyViewScopeProvider
        ControllerEvent.DESTROY -> destroyScopeProvider
        else -> throw RuntimeException("Scope for event ${event.name} wasn't created")
    }
-----------------------
    fun Completable.autoDisposable(event: ControllerEvent? = null): CompletableSubscribeProxy =
    observeOn(AndroidSchedulers.mainThread())
        .autoDisposable(getScopeProvider(event))
    private val scopeProvider: ControllerScopeProvider by lazy { ControllerScopeProvider.from(this) }

    private val destroyScopeProvider: ControllerScopeProvider by lazy {
      ControllerScopeProvider.from(
        this,
        ControllerEvent.DESTROY
      )
    }
...
    private fun getScopeProvider(event: ControllerEvent?): ControllerScopeProvider =
    when (event) {
        null -> scopeProvider
        ControllerEvent.DETACH -> detachScopeProvider
        ControllerEvent.DESTROY_VIEW -> destroyViewScopeProvider
        ControllerEvent.DESTROY -> destroyScopeProvider
        else -> throw RuntimeException("Scope for event ${event.name} wasn't created")
    }

riverpod FutureProvider will keep firing after adding .family modifier

copy iconCopydownload iconDownload
For families to work correctly, it is critical for the parameter passed to a
provider to have a consistent hashCode and ==.
class ExtraCostParameter extends Equatable {
  final List<String> cartCodesList;

  const ExtraCostParameter({required this.cartCodesList});

  @override
  List<Object?> get props => [cartCodesList];
}
final additionalCostsProvider = FutureProvider.autoDispose.family<List<ExtraCost>, ExtraCostParameter>((ref, param) {
  final cartAPI = ref.watch(cartAPIProvider);
  return cartAPI.getAdditionalCosts(cartCodes: param.cartCodesList);
});
-----------------------
For families to work correctly, it is critical for the parameter passed to a
provider to have a consistent hashCode and ==.
class ExtraCostParameter extends Equatable {
  final List<String> cartCodesList;

  const ExtraCostParameter({required this.cartCodesList});

  @override
  List<Object?> get props => [cartCodesList];
}
final additionalCostsProvider = FutureProvider.autoDispose.family<List<ExtraCost>, ExtraCostParameter>((ref, param) {
  final cartAPI = ref.watch(cartAPIProvider);
  return cartAPI.getAdditionalCosts(cartCodes: param.cartCodesList);
});
-----------------------
For families to work correctly, it is critical for the parameter passed to a
provider to have a consistent hashCode and ==.
class ExtraCostParameter extends Equatable {
  final List<String> cartCodesList;

  const ExtraCostParameter({required this.cartCodesList});

  @override
  List<Object?> get props => [cartCodesList];
}
final additionalCostsProvider = FutureProvider.autoDispose.family<List<ExtraCost>, ExtraCostParameter>((ref, param) {
  final cartAPI = ref.watch(cartAPIProvider);
  return cartAPI.getAdditionalCosts(cartCodes: param.cartCodesList);
});

How to convert a Stream to a Listenable in Flutter?

copy iconCopydownload iconDownload
  // Somewhere in main.dart I register my dependencies with Provider:

      Provider(
        create: (context) =>  AuthService(//pass whatever),
     // ...

  // Somewhere in my *stateful* App Widget' State:
  // ...
  late ValueListenable<bool> isLoggedInListenable;

  @override
  void initState(){
    // locate my authService Instance
    final authService = context.read<AuthService>();
    // as with anything that uses a stream, you need some kind of initial value
    // "convert" the stream to a value listenable
    isLoggedInListenable = authService.isLoggedIn.toValueListenable(false);
    super.initState();
  }

  @override
  Widget build(BuildContext context){
    final router = GoRouter(
      refreshListenable: isLoggedInListenable,
      redirect: (GoRouterState state) {
        bool isLoggedIn = isLoggedInListenable.value;
      
        if (!isLoggedIn && !onAuthRoute) //redirect to /signin;
        // ...
      }
    );
    return MaterialApp.router(
      // ...
    );
  }
extension StreamExtensions<T> on Stream<T> {
  ValueListenable<T> toValueNotifier(
    T initialValue, {
    bool Function(T previous, T current)? notifyWhen,
  }) {
    final notifier = ValueNotifier<T>(initialValue);
    listen((value) {
      if (notifyWhen == null || notifyWhen(notifier.value, value)) {
        notifier.value = value;
      }
    });
    return notifier;
  }

  // Edit: added nullable version
  ValueListenable<T?> toNullableValueNotifier{
    bool Function(T? previous, T? current)? notifyWhen,
  }) {
    final notifier = ValueNotifier<T?>(null);
    listen((value) {
      if (notifyWhen == null || notifyWhen(notifier.value, value)) {
        notifier.value = value;
      }
    });
    return notifier;
  }

  Listenable toListenable() {
    final notifier = ChangeNotifier();
    listen((_) {
      // ignore: invalid_use_of_protected_member, invalid_use_of_visible_for_testing_member
      notifier.notifyListeners();
    });
    return notifier;
  }
}
extension BlocExtensions<T> on BlocBase<T> {
  Listenable asListenable() {
    final notifier = ChangeNotifier();
    stream.listen((_) {
      // ignore: invalid_use_of_protected_member, invalid_use_of_visible_for_testing_member
      notifier.notifyListeners();
    });
    return notifier;
  }

  ValueListenable<T> asValueListenable({
    BlocBuilderCondition? notifyWhen,
  }) {
    final notifier = ValueNotifier<T>(state);
    stream.listen((value) {
      if (notifyWhen == null || notifyWhen(notifier.value, value)) {
        notifier.value = value;
      }
    });
    return notifier;
  }
}
-----------------------
  // Somewhere in main.dart I register my dependencies with Provider:

      Provider(
        create: (context) =>  AuthService(//pass whatever),
     // ...

  // Somewhere in my *stateful* App Widget' State:
  // ...
  late ValueListenable<bool> isLoggedInListenable;

  @override
  void initState(){
    // locate my authService Instance
    final authService = context.read<AuthService>();
    // as with anything that uses a stream, you need some kind of initial value
    // "convert" the stream to a value listenable
    isLoggedInListenable = authService.isLoggedIn.toValueListenable(false);
    super.initState();
  }

  @override
  Widget build(BuildContext context){
    final router = GoRouter(
      refreshListenable: isLoggedInListenable,
      redirect: (GoRouterState state) {
        bool isLoggedIn = isLoggedInListenable.value;
      
        if (!isLoggedIn && !onAuthRoute) //redirect to /signin;
        // ...
      }
    );
    return MaterialApp.router(
      // ...
    );
  }
extension StreamExtensions<T> on Stream<T> {
  ValueListenable<T> toValueNotifier(
    T initialValue, {
    bool Function(T previous, T current)? notifyWhen,
  }) {
    final notifier = ValueNotifier<T>(initialValue);
    listen((value) {
      if (notifyWhen == null || notifyWhen(notifier.value, value)) {
        notifier.value = value;
      }
    });
    return notifier;
  }

  // Edit: added nullable version
  ValueListenable<T?> toNullableValueNotifier{
    bool Function(T? previous, T? current)? notifyWhen,
  }) {
    final notifier = ValueNotifier<T?>(null);
    listen((value) {
      if (notifyWhen == null || notifyWhen(notifier.value, value)) {
        notifier.value = value;
      }
    });
    return notifier;
  }

  Listenable toListenable() {
    final notifier = ChangeNotifier();
    listen((_) {
      // ignore: invalid_use_of_protected_member, invalid_use_of_visible_for_testing_member
      notifier.notifyListeners();
    });
    return notifier;
  }
}
extension BlocExtensions<T> on BlocBase<T> {
  Listenable asListenable() {
    final notifier = ChangeNotifier();
    stream.listen((_) {
      // ignore: invalid_use_of_protected_member, invalid_use_of_visible_for_testing_member
      notifier.notifyListeners();
    });
    return notifier;
  }

  ValueListenable<T> asValueListenable({
    BlocBuilderCondition? notifyWhen,
  }) {
    final notifier = ValueNotifier<T>(state);
    stream.listen((value) {
      if (notifyWhen == null || notifyWhen(notifier.value, value)) {
        notifier.value = value;
      }
    });
    return notifier;
  }
}
-----------------------
  // Somewhere in main.dart I register my dependencies with Provider:

      Provider(
        create: (context) =>  AuthService(//pass whatever),
     // ...

  // Somewhere in my *stateful* App Widget' State:
  // ...
  late ValueListenable<bool> isLoggedInListenable;

  @override
  void initState(){
    // locate my authService Instance
    final authService = context.read<AuthService>();
    // as with anything that uses a stream, you need some kind of initial value
    // "convert" the stream to a value listenable
    isLoggedInListenable = authService.isLoggedIn.toValueListenable(false);
    super.initState();
  }

  @override
  Widget build(BuildContext context){
    final router = GoRouter(
      refreshListenable: isLoggedInListenable,
      redirect: (GoRouterState state) {
        bool isLoggedIn = isLoggedInListenable.value;
      
        if (!isLoggedIn && !onAuthRoute) //redirect to /signin;
        // ...
      }
    );
    return MaterialApp.router(
      // ...
    );
  }
extension StreamExtensions<T> on Stream<T> {
  ValueListenable<T> toValueNotifier(
    T initialValue, {
    bool Function(T previous, T current)? notifyWhen,
  }) {
    final notifier = ValueNotifier<T>(initialValue);
    listen((value) {
      if (notifyWhen == null || notifyWhen(notifier.value, value)) {
        notifier.value = value;
      }
    });
    return notifier;
  }

  // Edit: added nullable version
  ValueListenable<T?> toNullableValueNotifier{
    bool Function(T? previous, T? current)? notifyWhen,
  }) {
    final notifier = ValueNotifier<T?>(null);
    listen((value) {
      if (notifyWhen == null || notifyWhen(notifier.value, value)) {
        notifier.value = value;
      }
    });
    return notifier;
  }

  Listenable toListenable() {
    final notifier = ChangeNotifier();
    listen((_) {
      // ignore: invalid_use_of_protected_member, invalid_use_of_visible_for_testing_member
      notifier.notifyListeners();
    });
    return notifier;
  }
}
extension BlocExtensions<T> on BlocBase<T> {
  Listenable asListenable() {
    final notifier = ChangeNotifier();
    stream.listen((_) {
      // ignore: invalid_use_of_protected_member, invalid_use_of_visible_for_testing_member
      notifier.notifyListeners();
    });
    return notifier;
  }

  ValueListenable<T> asValueListenable({
    BlocBuilderCondition? notifyWhen,
  }) {
    final notifier = ValueNotifier<T>(state);
    stream.listen((value) {
      if (notifyWhen == null || notifyWhen(notifier.value, value)) {
        notifier.value = value;
      }
    });
    return notifier;
  }
}
-----------------------
GoRouterRefreshStream(_fooBloc.stream)

Flutter make http api call when Firestore document changed

copy iconCopydownload iconDownload
   var profileUser;
    userValue?.getFirestoreUser().listen((event) {
      profileUser = dbProvider!.getProfile();
    });

    if (profileUser) {
      return profileUser;
    } else {
      return Future.value(null);
    }
   var profileUser = (await userValue?.getFirestoreUser().first)!.getProfile();
    if (profileUser) {
      return profileUser;
    } else {
      return Future.value(null);
    }
-----------------------
   var profileUser;
    userValue?.getFirestoreUser().listen((event) {
      profileUser = dbProvider!.getProfile();
    });

    if (profileUser) {
      return profileUser;
    } else {
      return Future.value(null);
    }
   var profileUser = (await userValue?.getFirestoreUser().first)!.getProfile();
    if (profileUser) {
      return profileUser;
    } else {
      return Future.value(null);
    }

Firebase Flutter Riverpod: How do I get the documentID from Firebase when using Riverpod to map values across a model? Code Included

copy iconCopydownload iconDownload
    Future<dynamic> createRestaurantRecord(
      String id, Map<String, dynamic> data) async {
    return await _firestore.doc('restaurants/$id').set(data);
    }
-----------------------
    Stream<List<RestaurantModel>> restaurantModel() {
    return _firebase.collection('restaurantsPensacola').snapshots().map(
        (event) => event.docs.map((e) => RestaurantModel.fromFirebase(e.data(), e.id)).toList());
  }
import 'package:cloud_firestore/cloud_firestore.dart';

class RestaurantModel {
  final String? name;
  final String? phone;
  final String? fullAddress;
  final String? yearsInBusiness;
  final String? priceRange;
  final String? websiteLink;
  final String? id;

  RestaurantModel({
    required this.name,
    required this.phone,
    required this.fullAddress,
    required this.yearsInBusiness,
    required this.priceRange,
    required this.websiteLink,
    required this.id,
  });

  factory RestaurantModel.fromFirebase(
      Map<String, dynamic> restaurantModel, String documentIDFromFirebase) {
    return RestaurantModel(
      name: restaurantModel['name'],
      phone: restaurantModel['phone'],
      fullAddress: restaurantModel['fullAddress'],
      yearsInBusiness: restaurantModel['yearsInBusiness'],
      priceRange: restaurantModel['priceRange'],
      websiteLink: restaurantModel['websiteLink'],
      id: documentIDFromFirebase,
    );
  }
}

-----------------------
    Stream<List<RestaurantModel>> restaurantModel() {
    return _firebase.collection('restaurantsPensacola').snapshots().map(
        (event) => event.docs.map((e) => RestaurantModel.fromFirebase(e.data(), e.id)).toList());
  }
import 'package:cloud_firestore/cloud_firestore.dart';

class RestaurantModel {
  final String? name;
  final String? phone;
  final String? fullAddress;
  final String? yearsInBusiness;
  final String? priceRange;
  final String? websiteLink;
  final String? id;

  RestaurantModel({
    required this.name,
    required this.phone,
    required this.fullAddress,
    required this.yearsInBusiness,
    required this.priceRange,
    required this.websiteLink,
    required this.id,
  });

  factory RestaurantModel.fromFirebase(
      Map<String, dynamic> restaurantModel, String documentIDFromFirebase) {
    return RestaurantModel(
      name: restaurantModel['name'],
      phone: restaurantModel['phone'],
      fullAddress: restaurantModel['fullAddress'],
      yearsInBusiness: restaurantModel['yearsInBusiness'],
      priceRange: restaurantModel['priceRange'],
      websiteLink: restaurantModel['websiteLink'],
      id: documentIDFromFirebase,
    );
  }
}

Flutter : isolate the right hand of Future&lt;Either&gt;

copy iconCopydownload iconDownload
Future<Either<ApiFailures, List<CourseModel>>>
FutureProvider.autoDispose.family<List<CourseModel>
return _courseRepository.activeCourses(yearId);
final result= _courseRepository.activeCourses(yearId);
if(result.isRight()){
return result.gerOrElse(()=>null);
}else{
///handle left result
}
-----------------------
Future<Either<ApiFailures, List<CourseModel>>>
FutureProvider.autoDispose.family<List<CourseModel>
return _courseRepository.activeCourses(yearId);
final result= _courseRepository.activeCourses(yearId);
if(result.isRight()){
return result.gerOrElse(()=>null);
}else{
///handle left result
}
-----------------------
Future<Either<ApiFailures, List<CourseModel>>>
FutureProvider.autoDispose.family<List<CourseModel>
return _courseRepository.activeCourses(yearId);
final result= _courseRepository.activeCourses(yearId);
if(result.isRight()){
return result.gerOrElse(()=>null);
}else{
///handle left result
}
-----------------------
Future<Either<ApiFailures, List<CourseModel>>>
FutureProvider.autoDispose.family<List<CourseModel>
return _courseRepository.activeCourses(yearId);
final result= _courseRepository.activeCourses(yearId);
if(result.isRight()){
return result.gerOrElse(()=>null);
}else{
///handle left result
}
-----------------------
final activeCourseProvider = FutureProvider.autoDispose.family<List<CourseModel>, int>((ref, yearId) {
  final _courseRepository = ref.watch(coursesRepositoryProvider);
  return _courseRepository.fold<List<CourseModel>>(
    (ApiFailures failure) => {
      // Handle failure
      return [];
    },
    (List<CourseModel> r) => r
  );
});

Mapping Firebase streams in flutter

copy iconCopydownload iconDownload
return stream.map((snapshot) => snapshot.docs.map((doc) =>
Trxns.fromFirestore(doc.data() as Map<String, dynamic>)).toList());

How can i change Container color with GestureDetector and RiverPod

copy iconCopydownload iconDownload
context.read(newTasksProvider.notifier).setType()
GestureDetector(
    onTap: context.read(newTasksProvider.notifier).setType,
    child: Container(
        decoration: BoxDecoration(
        color: type == home
            ? theme.colorScheme.primaryVariant
            : Colors.transparent,
        borderRadius: BorderRadius.circular(50),
        ),
    ),
),
-----------------------
context.read(newTasksProvider.notifier).setType()
GestureDetector(
    onTap: context.read(newTasksProvider.notifier).setType,
    child: Container(
        decoration: BoxDecoration(
        color: type == home
            ? theme.colorScheme.primaryVariant
            : Colors.transparent,
        borderRadius: BorderRadius.circular(50),
        ),
    ),
),
-----------------------
class NewTasksNotifier extends StateNotifier<NewTasksState> {
  NewTasksNotifier() : super(NewTasksState(type: "work"));

  void setType() {
    if (state.type == "work")
      state = state.copyWith(
        type: "home",
      );
    else
      state = state.copyWith(
        type: "work",
      );
  }
}

final newTasksProvider =
    StateNotifierProvider.autoDispose<NewTasksNotifier, NewTasksState>(
        (ref) => NewTasksNotifier());

import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

import 'new_tasks_state.dart';

class ColorCOntainer extends StatelessWidget {
  const ColorCOntainer({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          Consumer(
            builder: (context, watch, child) {
              final type = watch(newTasksProvider);

              return GestureDetector(
                onTap: () {
                  print("tapped ${type.type}");

                  context.read(newTasksProvider.notifier).setType();
                },
                child: Container(
                  width: 100,
                  height: 100,
                  decoration: BoxDecoration(
                    color:
                        type.type == "home" ? Colors.pink : Colors.cyanAccent,
                    borderRadius: BorderRadius.circular(50),
                  ),
                  child: Center(child: Text("btn")),
                ),
              );
            },
          ),
        ],
      ),
    );
  }
}
-----------------------
class NewTasksNotifier extends StateNotifier<NewTasksState> {
  NewTasksNotifier() : super(NewTasksState(type: "work"));

  void setType() {
    if (state.type == "work")
      state = state.copyWith(
        type: "home",
      );
    else
      state = state.copyWith(
        type: "work",
      );
  }
}

final newTasksProvider =
    StateNotifierProvider.autoDispose<NewTasksNotifier, NewTasksState>(
        (ref) => NewTasksNotifier());

import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

import 'new_tasks_state.dart';

class ColorCOntainer extends StatelessWidget {
  const ColorCOntainer({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          Consumer(
            builder: (context, watch, child) {
              final type = watch(newTasksProvider);

              return GestureDetector(
                onTap: () {
                  print("tapped ${type.type}");

                  context.read(newTasksProvider.notifier).setType();
                },
                child: Container(
                  width: 100,
                  height: 100,
                  decoration: BoxDecoration(
                    color:
                        type.type == "home" ? Colors.pink : Colors.cyanAccent,
                    borderRadius: BorderRadius.circular(50),
                  ),
                  child: Center(child: Text("btn")),
                ),
              );
            },
          ),
        ],
      ),
    );
  }
}

AutoDisposeStreamProvider is not being disposed at loggin out

copy iconCopydownload iconDownload
final AutoDisposeStreamProvider<List<fc_types.Room>> roomsListProvider =
    StreamProvider.autoDispose<List<fc_types.Room>>(
  (_) => FirebaseChatCore.instance.rooms(),
  name: "List Rooms Provider",
);
  ref.onDispose(() => rooms.close());
-----------------------
final AutoDisposeStreamProvider<List<fc_types.Room>> roomsListProvider =
    StreamProvider.autoDispose<List<fc_types.Room>>(
  (_) => FirebaseChatCore.instance.rooms(),
  name: "List Rooms Provider",
);
  ref.onDispose(() => rooms.close());
-----------------------
final messageProvider = StreamProvider.autoDispose<String>((ref) async* {
  // Open the connection
  final channel = IOWebSocketChannel.connect('ws://echo.websocket.org');

  // Close the connection when the stream is destroyed
  ref.onDispose(() => channel.sink.close());

  // Parse the value received and emit a Message instance
  await for (final value in channel.stream) {
    yield value.toString();
  }
});
final AutoDisposeStreamProvider<List<fc_types.Room>> roomsListProvider =
    StreamProvider.autoDispose<List<fc_types.Room>>(
  (_) => FirebaseChatCore.instance.rooms(),
  name: "List Rooms Provider",
);
-----------------------
final messageProvider = StreamProvider.autoDispose<String>((ref) async* {
  // Open the connection
  final channel = IOWebSocketChannel.connect('ws://echo.websocket.org');

  // Close the connection when the stream is destroyed
  ref.onDispose(() => channel.sink.close());

  // Parse the value received and emit a Message instance
  await for (final value in channel.stream) {
    yield value.toString();
  }
});
final AutoDisposeStreamProvider<List<fc_types.Room>> roomsListProvider =
    StreamProvider.autoDispose<List<fc_types.Room>>(
  (_) => FirebaseChatCore.instance.rooms(),
  name: "List Rooms Provider",
);

I want to use pull to refresh on a Listview that is built from a Riverpod Model provider that gets it's data from a Future Provider

copy iconCopydownload iconDownload
RefreshIndicator(
   onRefresh: () async => context.refresh(dataProvider),
   child: WalletList(wallets: wallet.allWalletItems),
);

Community Discussions

Trending Discussions on AutoDispose
  • How to upgrade bluelinelabs/Conductor version 3.1.4 from version 3.0.0
  • riverpod FutureProvider will keep firing after adding .family modifier
  • How to convert a Stream to a Listenable in Flutter?
  • Flutter make http api call when Firestore document changed
  • Firebase Flutter Riverpod: How do I get the documentID from Firebase when using Riverpod to map values across a model? Code Included
  • Flutter : isolate the right hand of Future&lt;Either&gt;
  • Mapping Firebase streams in flutter
  • How can i change Container color with GestureDetector and RiverPod
  • AutoDisposeStreamProvider is not being disposed at loggin out
  • I want to use pull to refresh on a Listview that is built from a Riverpod Model provider that gets it's data from a Future Provider
Trending Discussions on AutoDispose

QUESTION

How to upgrade bluelinelabs/Conductor version 3.1.4 from version 3.0.0

Asked 2022-Mar-31 at 10:09

I'm trying to migrate from version 3.0.0 that used conductor-rxlifecycle to version 3.1.4 that is using conductor-archlifecycle and conductor-autodispose.

my current code has extension functions that binds to the lifecycle - and I'm trying to understand what is the code change needed to adjust it to archlifecycle and auto-dispose.

I would appreciate some help here - couldn't figure it out from the demo code.

conductor-archlifecycle demo

conductor-autodispose demo

protected fun <C : RxController> Completable.bindToController(controller: C): Completable =
    observeOn(AndroidSchedulers.mainThread()).compose(controller.bindToLifecycle<Any>())

protected fun <C : RxController> Completable.bindUntil(controller: C, event: ControllerEvent): Completable =
    observeOn(AndroidSchedulers.mainThread()).compose(controller.bindUntilEvent<Any>(event))

I assume that the controller type should be LifecycleController instead of RxController, but I don't understand what is the replacement of bindToLifecycle

I opened this issue , but I'm trying to get some help here as well

ANSWER

Answered 2022-Mar-31 at 10:09

This is the change I did to my code to match the new Conductor version:

The 2 functions above were replaced by this function:

    fun Completable.autoDisposable(event: ControllerEvent? = null): CompletableSubscribeProxy =
    observeOn(AndroidSchedulers.mainThread())
        .autoDisposable(getScopeProvider(event))

Note that the return type is now CompletableSubscribeProxy and not Completable so the location of the call in the chain might need to be changed.

I create different scopes:

    private val scopeProvider: ControllerScopeProvider by lazy { ControllerScopeProvider.from(this) }

    private val destroyScopeProvider: ControllerScopeProvider by lazy {
      ControllerScopeProvider.from(
        this,
        ControllerEvent.DESTROY
      )
    }
...

And this is how getScopeProvider looks

    private fun getScopeProvider(event: ControllerEvent?): ControllerScopeProvider =
    when (event) {
        null -> scopeProvider
        ControllerEvent.DETACH -> detachScopeProvider
        ControllerEvent.DESTROY_VIEW -> destroyViewScopeProvider
        ControllerEvent.DESTROY -> destroyScopeProvider
        else -> throw RuntimeException("Scope for event ${event.name} wasn't created")
    }

Source https://stackoverflow.com/questions/71557321

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install AutoDispose

You can download it from GitHub.
You can use AutoDispose like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the AutoDispose component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Share this Page

share link
Consider Popular Reactive Programming Libraries
Compare Reactive Programming Libraries with Highest Support
Compare Reactive Programming Libraries with Highest Quality
Compare Reactive Programming Libraries with Highest Security
Compare Reactive Programming Libraries with Permissive License
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.