@@ -7,6 +7,7 @@ import 'package:nextcloud/nextcloud.dart';
77import 'package:nextcloud_cookbook_flutter/src/blocs/authentication/authentication_bloc.dart' ;
88import 'package:nextcloud_cookbook_flutter/src/models/app_authentication.dart' ;
99import 'package:nextcloud_cookbook_flutter/src/services/services.dart' ;
10+ import 'package:nextcloud_cookbook_flutter/src/util/nextcloud_login_qr_util.dart' ;
1011import 'package:nextcloud_cookbook_flutter/src/util/url_validator.dart' ;
1112
1213part 'login_event.dart' ;
@@ -17,6 +18,7 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {
1718 required this .authenticationBloc,
1819 }) : super (const LoginState ()) {
1920 on < LoginFlowStart > (_mapLoginFlowStartEventToState);
21+ on < LoginQRScenned > (_mapLoginQRScannedEventToState);
2022 }
2123 final UserRepository userRepository = UserRepository ();
2224 final AuthenticationBloc authenticationBloc;
@@ -54,4 +56,27 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {
5456 emit (LoginState (status: LoginStatus .failure, error: e.toString ()));
5557 }
5658 }
59+
60+ Future <void > _mapLoginQRScannedEventToState (
61+ LoginQRScenned event,
62+ Emitter <LoginState > emit,
63+ ) async {
64+ assert (event.uri.isScheme ('nc' ));
65+ try {
66+ final auth = parseNCLoginQR (event.uri);
67+
68+ authenticationBloc.add (
69+ LoggedIn (
70+ appAuthentication: AppAuthentication (
71+ server: auth['server' ]! ,
72+ loginName: auth['user' ]! ,
73+ appPassword: auth['password' ]! ,
74+ isSelfSignedCertificate: false ,
75+ ),
76+ ),
77+ );
78+ } catch (e) {
79+ emit (LoginState (status: LoginStatus .failure, error: e.toString ()));
80+ }
81+ }
5782}
0 commit comments