-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
81 changed files
with
2,793 additions
and
1,479 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:thingsboard_app/core/auth/login/bloc/bloc.dart'; | ||
import 'package:thingsboard_app/core/context/tb_context.dart'; | ||
import 'package:thingsboard_app/modules/version/route/version_route.dart'; | ||
import 'package:thingsboard_app/modules/version/route/version_route_arguments.dart'; | ||
import 'package:thingsboard_app/thingsboard_client.dart'; | ||
|
||
class AuthBloc extends Bloc<AuthEvent, AuthState> { | ||
AuthBloc({ | ||
required this.tbClient, | ||
required this.tbContext, | ||
}) : super(const AuthLoadingState()) { | ||
on(_onEvent); | ||
} | ||
|
||
final ThingsboardClient tbClient; | ||
final TbContext tbContext; | ||
|
||
Future<void> _onEvent(AuthEvent event, Emitter<AuthState> emit) async { | ||
switch (event) { | ||
case AuthFetchEvent(): | ||
try { | ||
final loginInfo = | ||
await tbClient.getMobileService().getLoginMobileInfo( | ||
MobileInfoQuery( | ||
packageName: event.packageName, | ||
platformType: event.platformType, | ||
), | ||
); | ||
|
||
if (loginInfo != null) { | ||
final versionInfo = loginInfo.versionInfo; | ||
if (versionInfo != null) { | ||
if (tbContext.version.versionInt() < | ||
(versionInfo.minVersion?.versionInt() ?? 0)) { | ||
tbContext.navigateTo( | ||
VersionRoutes.updateRequiredRoutePath, | ||
clearStack: true, | ||
replace: true, | ||
routeSettings: RouteSettings( | ||
arguments: VersionRouteArguments( | ||
versionInfo: versionInfo, | ||
storeInfo: loginInfo.storeInfo, | ||
), | ||
), | ||
); | ||
return; | ||
} | ||
} | ||
|
||
emit(AuthDataState(oAuthClients: loginInfo.oAuth2Clients)); | ||
} else { | ||
emit(const AuthDataState(oAuthClients: [])); | ||
} | ||
} catch (_) { | ||
emit(const AuthDataState(oAuthClients: [])); | ||
} | ||
|
||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:thingsboard_app/thingsboard_client.dart' show PlatformType; | ||
|
||
sealed class AuthEvent extends Equatable { | ||
const AuthEvent(); | ||
|
||
@override | ||
List<Object?> get props => []; | ||
} | ||
|
||
final class AuthFetchEvent extends AuthEvent { | ||
const AuthFetchEvent({ | ||
required this.packageName, | ||
required this.platformType, | ||
}); | ||
|
||
final String packageName; | ||
final PlatformType platformType; | ||
|
||
@override | ||
List<Object?> get props => [packageName, platformType]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:thingsboard_app/thingsboard_client.dart' show OAuth2ClientInfo; | ||
|
||
sealed class AuthState extends Equatable { | ||
const AuthState(); | ||
|
||
@override | ||
List<Object?> get props => []; | ||
} | ||
|
||
final class AuthLoadingState extends AuthState { | ||
const AuthLoadingState(); | ||
} | ||
|
||
final class AuthDataState extends AuthState { | ||
const AuthDataState({ | ||
required this.oAuthClients, | ||
}); | ||
|
||
final List<OAuth2ClientInfo> oAuthClients; | ||
|
||
@override | ||
List<Object?> get props => [oAuthClients]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export 'auth_bloc.dart'; | ||
export 'auth_events.dart'; | ||
export 'auth_states.dart'; |
Oops, something went wrong.