-
Notifications
You must be signed in to change notification settings - Fork 78
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
Comments
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,
)), |
The documentation is linked in the readme. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried all the things to do integrate in app update but it is not working at all.
Things i tried:
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
The text was updated successfully, but these errors were encountered: