Skip to content

Commit

Permalink
App crash fixed (#242)
Browse files Browse the repository at this point in the history
Signed-off-by: Piyush7034 <piyushshukla2100@gmail.com>
  • Loading branch information
Piyush7034 authored Jan 5, 2024
1 parent 275e0c2 commit af30b94
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private AuthResponsePigeon.AuthResponse getAuthErrorResponse(String errorCode) {
.setIsDefault(false)
.setIsOfficer(false)
.setIsSupervisor(false)
.setIsOperator(false)
.setErrorCode(errorCode)
.build();

Expand Down
34 changes: 13 additions & 21 deletions ios/Runner/pigeon.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,26 @@

NS_ASSUME_NONNULL_BEGIN

@class AuthResponse;
@class TransliterationOptions;

@interface AuthResponse : NSObject
@interface TransliterationOptions : NSObject
/// `init` unavailable to enforce nonnull fields, see the `make` class method.
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)makeWithResponse:(NSString *)response
username:(NSString *)username
isOfficer:(NSNumber *)isOfficer
isDefault:(NSNumber *)isDefault
isSupervisor:(NSNumber *)isSupervisor
isOperator:(NSNumber *)isOperator
errorCode:(nullable NSString *)errorCode;
@property(nonatomic, copy) NSString * response;
@property(nonatomic, copy) NSString * username;
@property(nonatomic, strong) NSNumber * isOfficer;
@property(nonatomic, strong) NSNumber * isDefault;
@property(nonatomic, strong) NSNumber * isSupervisor;
@property(nonatomic, strong) NSNumber * isOperator;
@property(nonatomic, copy, nullable) NSString * errorCode;
+ (instancetype)makeWithInput:(NSString *)input
sourceLanguage:(NSString *)sourceLanguage
targetLanguage:(NSString *)targetLanguage;
@property(nonatomic, copy) NSString * input;
@property(nonatomic, copy) NSString * sourceLanguage;
@property(nonatomic, copy) NSString * targetLanguage;
@end

/// The codec used by AuthResponseApi.
NSObject<FlutterMessageCodec> *AuthResponseApiGetCodec(void);
/// The codec used by TransliterationApi.
NSObject<FlutterMessageCodec> *TransliterationApiGetCodec(void);

@protocol AuthResponseApi
- (void)loginUsername:(NSString *)username password:(NSString *)password isConnected:(NSNumber *)isConnected completion:(void (^)(AuthResponse *_Nullable, FlutterError *_Nullable))completion;
@protocol TransliterationApi
- (void)transliterateOptions:(TransliterationOptions *)options completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion;
@end

extern void AuthResponseApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<AuthResponseApi> *_Nullable api);
extern void TransliterationApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<TransliterationApi> *_Nullable api);

NS_ASSUME_NONNULL_END
105 changes: 42 additions & 63 deletions ios/Runner/pigeon.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,81 +26,62 @@ static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) {
return (result == [NSNull null]) ? nil : result;
}

@interface AuthResponse ()
+ (AuthResponse *)fromList:(NSArray *)list;
+ (nullable AuthResponse *)nullableFromList:(NSArray *)list;
@interface TransliterationOptions ()
+ (TransliterationOptions *)fromList:(NSArray *)list;
+ (nullable TransliterationOptions *)nullableFromList:(NSArray *)list;
- (NSArray *)toList;
@end

@implementation AuthResponse
+ (instancetype)makeWithResponse:(NSString *)response
username:(NSString *)username
isOfficer:(NSNumber *)isOfficer
isDefault:(NSNumber *)isDefault
isSupervisor:(NSNumber *)isSupervisor
isOperator:(NSNumber *)isOperator
errorCode:(nullable NSString *)errorCode {
AuthResponse* pigeonResult = [[AuthResponse alloc] init];
pigeonResult.response = response;
pigeonResult.username = username;
pigeonResult.isOfficer = isOfficer;
pigeonResult.isDefault = isDefault;
pigeonResult.isSupervisor = isSupervisor;
pigeonResult.isOperator = isOperator;
pigeonResult.errorCode = errorCode;
@implementation TransliterationOptions
+ (instancetype)makeWithInput:(NSString *)input
sourceLanguage:(NSString *)sourceLanguage
targetLanguage:(NSString *)targetLanguage {
TransliterationOptions* pigeonResult = [[TransliterationOptions alloc] init];
pigeonResult.input = input;
pigeonResult.sourceLanguage = sourceLanguage;
pigeonResult.targetLanguage = targetLanguage;
return pigeonResult;
}
+ (AuthResponse *)fromList:(NSArray *)list {
AuthResponse *pigeonResult = [[AuthResponse alloc] init];
pigeonResult.response = GetNullableObjectAtIndex(list, 0);
NSAssert(pigeonResult.response != nil, @"");
pigeonResult.username = GetNullableObjectAtIndex(list, 1);
NSAssert(pigeonResult.username != nil, @"");
pigeonResult.isOfficer = GetNullableObjectAtIndex(list, 2);
NSAssert(pigeonResult.isOfficer != nil, @"");
pigeonResult.isDefault = GetNullableObjectAtIndex(list, 3);
NSAssert(pigeonResult.isDefault != nil, @"");
pigeonResult.isSupervisor = GetNullableObjectAtIndex(list, 4);
NSAssert(pigeonResult.isSupervisor != nil, @"");
pigeonResult.isOperator = GetNullableObjectAtIndex(list, 5);
NSAssert(pigeonResult.isOperator != nil, @"");
pigeonResult.errorCode = GetNullableObjectAtIndex(list, 6);
+ (TransliterationOptions *)fromList:(NSArray *)list {
TransliterationOptions *pigeonResult = [[TransliterationOptions alloc] init];
pigeonResult.input = GetNullableObjectAtIndex(list, 0);
NSAssert(pigeonResult.input != nil, @"");
pigeonResult.sourceLanguage = GetNullableObjectAtIndex(list, 1);
NSAssert(pigeonResult.sourceLanguage != nil, @"");
pigeonResult.targetLanguage = GetNullableObjectAtIndex(list, 2);
NSAssert(pigeonResult.targetLanguage != nil, @"");
return pigeonResult;
}
+ (nullable AuthResponse *)nullableFromList:(NSArray *)list {
return (list) ? [AuthResponse fromList:list] : nil;
+ (nullable TransliterationOptions *)nullableFromList:(NSArray *)list {
return (list) ? [TransliterationOptions fromList:list] : nil;
}
- (NSArray *)toList {
return @[
(self.response ?: [NSNull null]),
(self.username ?: [NSNull null]),
(self.isOfficer ?: [NSNull null]),
(self.isDefault ?: [NSNull null]),
(self.isSupervisor ?: [NSNull null]),
(self.isOperator ?: [NSNull null]),
(self.errorCode ?: [NSNull null]),
(self.input ?: [NSNull null]),
(self.sourceLanguage ?: [NSNull null]),
(self.targetLanguage ?: [NSNull null]),
];
}
@end

@interface AuthResponseApiCodecReader : FlutterStandardReader
@interface TransliterationApiCodecReader : FlutterStandardReader
@end
@implementation AuthResponseApiCodecReader
@implementation TransliterationApiCodecReader
- (nullable id)readValueOfType:(UInt8)type {
switch (type) {
case 128:
return [AuthResponse fromList:[self readValue]];
return [TransliterationOptions fromList:[self readValue]];
default:
return [super readValueOfType:type];
}
}
@end

@interface AuthResponseApiCodecWriter : FlutterStandardWriter
@interface TransliterationApiCodecWriter : FlutterStandardWriter
@end
@implementation AuthResponseApiCodecWriter
@implementation TransliterationApiCodecWriter
- (void)writeValue:(id)value {
if ([value isKindOfClass:[AuthResponse class]]) {
if ([value isKindOfClass:[TransliterationOptions class]]) {
[self writeByte:128];
[self writeValue:[value toList]];
} else {
Expand All @@ -109,42 +90,40 @@ - (void)writeValue:(id)value {
}
@end

@interface AuthResponseApiCodecReaderWriter : FlutterStandardReaderWriter
@interface TransliterationApiCodecReaderWriter : FlutterStandardReaderWriter
@end
@implementation AuthResponseApiCodecReaderWriter
@implementation TransliterationApiCodecReaderWriter
- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data {
return [[AuthResponseApiCodecWriter alloc] initWithData:data];
return [[TransliterationApiCodecWriter alloc] initWithData:data];
}
- (FlutterStandardReader *)readerWithData:(NSData *)data {
return [[AuthResponseApiCodecReader alloc] initWithData:data];
return [[TransliterationApiCodecReader alloc] initWithData:data];
}
@end

NSObject<FlutterMessageCodec> *AuthResponseApiGetCodec(void) {
NSObject<FlutterMessageCodec> *TransliterationApiGetCodec(void) {
static FlutterStandardMessageCodec *sSharedObject = nil;
static dispatch_once_t sPred = 0;
dispatch_once(&sPred, ^{
AuthResponseApiCodecReaderWriter *readerWriter = [[AuthResponseApiCodecReaderWriter alloc] init];
TransliterationApiCodecReaderWriter *readerWriter = [[TransliterationApiCodecReaderWriter alloc] init];
sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter];
});
return sSharedObject;
}

void AuthResponseApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<AuthResponseApi> *api) {
void TransliterationApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<TransliterationApi> *api) {
{
FlutterBasicMessageChannel *channel =
[[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.registration_client.AuthResponseApi.login"
initWithName:@"dev.flutter.pigeon.registration_client.TransliterationApi.transliterate"
binaryMessenger:binaryMessenger
codec:AuthResponseApiGetCodec()];
codec:TransliterationApiGetCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(loginUsername:password:isConnected:completion:)], @"AuthResponseApi api (%@) doesn't respond to @selector(loginUsername:password:isConnected:completion:)", api);
NSCAssert([api respondsToSelector:@selector(transliterateOptions:completion:)], @"TransliterationApi api (%@) doesn't respond to @selector(transliterateOptions:completion:)", api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
NSArray *args = message;
NSString *arg_username = GetNullableObjectAtIndex(args, 0);
NSString *arg_password = GetNullableObjectAtIndex(args, 1);
NSNumber *arg_isConnected = GetNullableObjectAtIndex(args, 2);
[api loginUsername:arg_username password:arg_password isConnected:arg_isConnected completion:^(AuthResponse *_Nullable output, FlutterError *_Nullable error) {
TransliterationOptions *arg_options = GetNullableObjectAtIndex(args, 0);
[api transliterateOptions:arg_options completion:^(NSString *_Nullable output, FlutterError *_Nullable error) {
callback(wrapResult(output, error));
}];
}];
Expand Down
4 changes: 0 additions & 4 deletions lib/ui/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,6 @@ class _LoginPageState extends State<LoginPage> with WidgetsBindingObserver {
snackbarText = AppLocalizations.of(context)!.center_inactive;
break;

case "DEFAULT_NOT_FOUND":
snackbarText = AppLocalizations.of(context)!.default_not_found;
break;

case "":
return;

Expand Down

0 comments on commit af30b94

Please sign in to comment.