-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add settings to Flutter App (#88)
* feat: get current session information * feat: create login flow * feat: login with email and password * feat: register with email and password * fix: handle all errors incl deserialization error * feat: logout & get session on home page init * feat: show session information * feat: add design and refactor blocs * fix: change package and folder name * fix: change package name * docs: update README.md * refactor: delete unused icon * refactor: remove unused packages * chore: format code * refactor: add missing package and delete unused test * feat: change password in settings * design: add padding to messages * feat: refresh session when updating settings * design: add assets' variants * feat: display settings dynamically * chore: create widgets * fix: chnge submit button value * chore: format code * chore: display components dynamically * chore: clean up and format code * fix: aal2 navigation * chore: remove unnecessary code * feat: sign in/up with google account on iOS * chore: add ios url scheme and web clientId * chore: fix typo and rename variables * chore: separate exception handlings * fix: prevent null exception * chore: delete unused assets & widgets * fix: remove pop & show provider buttons correctly * chore: separate exception handlings * chore: format code * chore: change package name and add auth packages * feat: add apple & google sign in * chore: delete unnecessary exception handling * feat: add flutter app Ory Network example (#82) * feat: get current session information * feat: create login flow * feat: login with email and password * feat: register with email and password * fix: handle all errors incl deserialization error * feat: logout & get session on home page init * feat: show session information * feat: add design and refactor blocs * fix: change package and folder name * fix: change package name * docs: update README.md * refactor: delete unused icon * refactor: remove unused packages * chore: format code * refactor: add missing package and delete unused test * chore: display components dynamically * chore: clean up and format code * fix: aal2 navigation * chore: remove unnecessary code * chore: fix typo and rename variables * chore: separate exception handlings * fix: prevent null exception * chore: delete unused assets and widgets * chore: remove misleading widget * Update README.md * Update README.md * chore: add formatting * chore: add formatting * chore: regenerate freezed files * fix: rebuild settings page or reset buttons * chore: refactor auth state & add missing social login functionality * chore: use helpers to get nodes of group * fix: reset settings when navigating back * chore: delete build artifacts * fix: typo Co-authored-by: Jonas Hungershausen <jonas.hungershausen@gmail.com> --------- Co-authored-by: Jonas Hungershausen <jonas.hungershausen@gmail.com>
- Loading branch information
1 parent
4aa769d
commit b23f3a2
Showing
51 changed files
with
1,506 additions
and
138 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
flutter-ory-network/android/app/src/main/kotlin/com/ory/flutter_ory_network/MainActivity.kt
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,6 @@ | ||
package com.ory.flutter_ory_network | ||
|
||
import io.flutter.embedding.android.FlutterActivity | ||
|
||
class MainActivity: FlutterActivity() { | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
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
128 changes: 128 additions & 0 deletions
128
flutter-ory-network/lib/blocs/settings/settings_bloc.dart
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,128 @@ | ||
// Copyright © 2023 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import 'package:bloc/bloc.dart'; | ||
import 'package:bloc_concurrency/bloc_concurrency.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
import 'package:ory_client/ory_client.dart'; | ||
import 'package:ory_network_flutter/repositories/auth.dart'; | ||
|
||
import '../../repositories/settings.dart'; | ||
import '../../services/exceptions.dart'; | ||
import '../auth/auth_bloc.dart'; | ||
|
||
part 'settings_event.dart'; | ||
part 'settings_state.dart'; | ||
|
||
part 'settings_bloc.freezed.dart'; | ||
|
||
class SettingsBloc extends Bloc<SettingsEvent, SettingsState> { | ||
final AuthBloc authBloc; | ||
final SettingsRepository repository; | ||
late SettingsEvent? _previousEvent; | ||
SettingsBloc({required this.authBloc, required this.repository}) | ||
: super(const SettingsState()) { | ||
on<CreateSettingsFlow>(_onCreateSettingsFlow); | ||
on<GetSettingsFlow>(_onGetSettingsFlow); | ||
on<ChangeSettingsNodeValue>(_onChangeNodeValue, transformer: sequential()); | ||
on<ResetSettings>(_onResetSettings); | ||
on<UpdateSettingsFlow>(_onUpdateSettingsFlow, transformer: sequential()); | ||
} | ||
|
||
@override | ||
void onEvent(SettingsEvent event) { | ||
super.onEvent(event); | ||
_previousEvent = event; | ||
} | ||
|
||
void retry() { | ||
if (_previousEvent != null) { | ||
add(_previousEvent!); | ||
} | ||
} | ||
|
||
_onChangeNodeValue( | ||
ChangeSettingsNodeValue event, Emitter<SettingsState> emit) { | ||
if (state.settingsFlow != null) { | ||
final newSettingsState = repository.changeNodeValue( | ||
settings: state.settingsFlow!, name: event.name, value: event.value); | ||
emit(state.copyWith(settingsFlow: newSettingsState, message: null)); | ||
} | ||
} | ||
|
||
_onResetSettings(ResetSettings event, Emitter<SettingsState> emit) async { | ||
if (state.settingsFlow != null) { | ||
emit(state.copyWith(isLoading: true)); | ||
final settings = | ||
await repository.getSettingsFlow(flowId: state.settingsFlow!.id); | ||
emit(state.copyWith( | ||
settingsFlow: settings, | ||
isSessionRefreshRequired: false, | ||
isLoading: false)); | ||
} | ||
} | ||
|
||
Future<void> _onUpdateSettingsFlow( | ||
UpdateSettingsFlow event, Emitter<SettingsState> emit) async { | ||
try { | ||
if (state.settingsFlow != null) { | ||
emit(state.copyWith( | ||
isLoading: true, isSessionRefreshRequired: false, message: null)); | ||
final settings = await repository.updateSettingsFlow( | ||
flowId: state.settingsFlow!.id, | ||
group: event.group, | ||
nodes: state.settingsFlow!.ui.nodes.toList()); | ||
emit(state.copyWith(isLoading: false, settingsFlow: settings)); | ||
} | ||
} on UnauthorizedException catch (_) { | ||
// change auth status as the user is not authenticated | ||
authBloc.add(ChangeAuthStatus(status: AuthStatus.unauthenticated)); | ||
} on FlowExpiredException catch (e) { | ||
// get new settings flow | ||
add(GetSettingsFlow(flowId: e.flowId)); | ||
} on SessionRefreshRequiredException catch (_) { | ||
// set session refresh required flag to navigate to login page | ||
emit(state.copyWith(isSessionRefreshRequired: true, isLoading: false)); | ||
} on UnknownException catch (e) { | ||
emit(state.copyWith(isLoading: false, message: e.message)); | ||
} catch (_) { | ||
emit(state.copyWith(isLoading: false)); | ||
} | ||
} | ||
|
||
Future<void> _onCreateSettingsFlow( | ||
SettingsEvent event, Emitter<SettingsState> emit) async { | ||
try { | ||
emit(state.copyWith(isLoading: true, message: null)); | ||
|
||
final settingsFlow = await repository.createSettingsFlow(); | ||
|
||
emit(state.copyWith(isLoading: false, settingsFlow: settingsFlow)); | ||
} on UnauthorizedException catch (_) { | ||
// change auth status as the user is not authenticated | ||
authBloc.add(ChangeAuthStatus(status: AuthStatus.unauthenticated)); | ||
} on UnknownException catch (e) { | ||
emit(state.copyWith(isLoading: false, message: e.message)); | ||
} catch (_) { | ||
emit(state.copyWith(isLoading: false)); | ||
} | ||
} | ||
|
||
Future<void> _onGetSettingsFlow( | ||
GetSettingsFlow event, Emitter<SettingsState> emit) async { | ||
try { | ||
emit(state.copyWith(isLoading: true)); | ||
final settingsFlow = | ||
await repository.getSettingsFlow(flowId: event.flowId); | ||
emit(state.copyWith(isLoading: false, settingsFlow: settingsFlow)); | ||
} on UnauthorizedException catch (_) { | ||
// change auth status as the user is not authenticated | ||
authBloc.add(ChangeAuthStatus(status: AuthStatus.unauthenticated)); | ||
} on UnknownException catch (e) { | ||
emit(state.copyWith(isLoading: false, message: e.message)); | ||
} catch (_) { | ||
emit(state.copyWith(isLoading: false)); | ||
} | ||
} | ||
} |
Oops, something went wrong.