Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage Documentation not available! #92

Closed
pishabh625 opened this issue Dec 15, 2022 · 2 comments
Closed

Usage Documentation not available! #92

pishabh625 opened this issue Dec 15, 2022 · 2 comments

Comments

@pishabh625
Copy link

I tried all the things to do integrate in app update but it is not working at all.
Things i tried:

  1. Testing using internal app sharing
  2. Added required dependencies
  • released one version of app which having(inAppUpdate package integrated)
  • released higher version of app than previous version(inAppUpdate package integrated)
    In internal testing....
    Issue:
    After doing all this things i am not getting promt for update inside older version of app.

Please help me if i am missing something or provide usage documentation atleast so that everyone can test the app easily without having any issue.

Thank you

@akshaynjarangal
Copy link
Contributor

akshaynjarangal commented Dec 21, 2022

Hey @pishabh625 check this out the code , hope u helpful

import 'dart:io';
import 'package:dartz/dartz.dart';
import 'package:in_app_update/in_app_update.dart';

// Function class
class CheckAppUpdateDataProvider {
  static Future<Either<MainFailures, AppUpdateInfo>> checkAppUpdate() async {
    try {
      if(Platform.isAndroid){
        final info = await InAppUpdate.checkForUpdate();
        return Right(info);
      }
      return const Left(MainFailures.formatExceptionFailure);
    } catch (exception) {
      return appUpdateexceptionHandler(exception);
    }
  }
}

// Repository class
class CheckAppUpdateRepository {
  static Future<Either<MainFailures, AppUpdateInfo>> checkInAppUpdate() async {
    final response = await CheckAppUpdateDataProvider.checkAppUpdate();
    return response.fold((failure) {
      return Left(failure);
    }, (success) {
      return Right(success);
    });
  }

//State check using bloc state management 

import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:in_app_update/in_app_update.dart';

import '../../data/repositories/check_app_update_repository.dart';
part 'check_app_update_event.dart';
part 'check_app_update_state.dart';

class CheckAppUpdateBloc
    extends Bloc<CheckAppUpdateEvent, CheckAppUpdateState> {
  CheckAppUpdateBloc()
      : super(CheckAppUpdateInitial()) {
    on<LoadCheckUpdate>((event, emit) async {
      final response = await CheckAppUpdateRepository.checkInAppUpdate();
      response.fold((failure) {
        emit(AppUpdateError());
      }, (success) {
        if (success.updateAvailability == UpdateAvailability.updateAvailable) {
          emit(AppUpdateAvailable());
        } else {
          emit(AppUpdateNotAvailable());
        }
      });
    });
  }
}


part of 'check_app_update_bloc.dart';


// ~~~~~~~~~~~~~~~~~~~~~~~~ event class ~~~~~~~~~~~~~~~
abstract class CheckAppUpdateEvent extends Equatable {
  const CheckAppUpdateEvent();

  @override
  List<Object> get props => [];
}

class LoadCheckUpdate extends CheckAppUpdateEvent{}



// ~~~~~~~~~~~~~~~~~~~~~~state class ~~~~~~~~~~~~~~~~

part of 'check_app_update_bloc.dart';

abstract class CheckAppUpdateState extends Equatable {
  const CheckAppUpdateState();
}

class CheckAppUpdateInitial extends CheckAppUpdateState {
  @override
  List<Object?> get props => [];
}

class AppUpdateAvailable extends CheckAppUpdateState{
  @override
  List<Object?> get props => [];
}

class AppUpdateNotAvailable extends CheckAppUpdateState{
   @override
  List<Object?> get props => [];
}

class AppUpdateError extends CheckAppUpdateState{
   @override
  List<Object?> get props => [];
}



// list the changes using bloc listener 
// Wrap the BlocListener with Material App

BlocListener<CheckAppUpdateBloc, CheckAppUpdateState>(
        listener: (context, state) async{
          if(state is AppUpdateAvailable){
           final result = await InAppUpdate.performImmediateUpdate();
           log("App Update Result : ${result.name}");
          }
        },
        child: MaterialApp(
          scaffoldMessengerKey: snackkey,
          )),

@jonasbark
Copy link
Owner

The documentation is linked in the readme.
https://developer.android.com/guide/playcore/in-app-updates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants