mirror of
https://github.com/StarCitizenToolBox/app.git
synced 2026-02-06 15:10:20 +00:00
feat: oidc support
This commit is contained in:
286
lib/ui/auth/auth_page.dart
Normal file
286
lib/ui/auth/auth_page.dart
Normal file
@@ -0,0 +1,286 @@
|
||||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:starcitizen_doctor/provider/party_room.dart';
|
||||
import 'package:starcitizen_doctor/ui/auth/auth_ui_model.dart';
|
||||
import 'package:starcitizen_doctor/ui/party_room/utils/party_room_utils.dart';
|
||||
import 'package:starcitizen_doctor/widgets/widgets.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
|
||||
class AuthPage extends HookConsumerWidget {
|
||||
final String? callbackUrl;
|
||||
final String? stateParameter;
|
||||
final String? nonce;
|
||||
|
||||
const AuthPage({super.key, this.callbackUrl, this.stateParameter, this.nonce});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final provider = authUIModelProvider(callbackUrl: callbackUrl, stateParameter: stateParameter, nonce: nonce);
|
||||
final model = ref.watch(provider);
|
||||
final modelNotifier = ref.read(provider.notifier);
|
||||
|
||||
final partyRoomState = ref.watch(partyRoomProvider);
|
||||
final userName = partyRoomState.auth.userInfo?.handleName ?? '未知用户';
|
||||
final userEmail = partyRoomState.auth.userInfo?.gameUserId ?? ''; // Using gameUserId as email-like identifier
|
||||
final avatarUrl = partyRoomState.auth.userInfo?.avatarUrl;
|
||||
final fullAvatarUrl = PartyRoomUtils.getAvatarUrl(avatarUrl);
|
||||
|
||||
useEffect(() {
|
||||
Future.microtask(() => modelNotifier.initialize());
|
||||
return null;
|
||||
}, const []);
|
||||
|
||||
return ContentDialog(
|
||||
constraints: const BoxConstraints(maxWidth: 450, maxHeight: 600),
|
||||
// Remove standard title to customize layout
|
||||
title: const SizedBox.shrink(),
|
||||
content: _buildBody(context, model, modelNotifier, userName, userEmail, fullAvatarUrl),
|
||||
actions: [
|
||||
if (model.error == null && model.isLoggedIn) ...[
|
||||
// Cancel button
|
||||
Button(onPressed: () => Navigator.of(context).pop(), child: const Text('拒绝')),
|
||||
// Allow button (Primary)
|
||||
FilledButton(
|
||||
onPressed: model.isLoading ? null : () => _handleAuthorize(context, ref, false),
|
||||
child: const Text('允许'),
|
||||
),
|
||||
] else ...[
|
||||
Button(onPressed: () => Navigator.of(context).pop(), child: const Text('关闭')),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(
|
||||
BuildContext context,
|
||||
AuthUIState state,
|
||||
AuthUIModel model,
|
||||
String userName,
|
||||
String userEmail,
|
||||
String? avatarUrl,
|
||||
) {
|
||||
if (state.isLoading) {
|
||||
return const SizedBox(height: 300, child: Center(child: ProgressRing()));
|
||||
}
|
||||
|
||||
if (state.isWaitingForConnection) {
|
||||
return SizedBox(
|
||||
height: 300,
|
||||
child: Center(
|
||||
child: Column(mainAxisSize: MainAxisSize.min, children: [const ProgressRing(), const SizedBox(height: 24)]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (state.error != null) {
|
||||
return SizedBox(
|
||||
height: 300,
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(FluentIcons.error_badge, size: 48, color: Colors.red),
|
||||
const SizedBox(height: 16),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: Text(
|
||||
state.error!,
|
||||
style: TextStyle(color: Colors.red, fontSize: 14),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
FilledButton(onPressed: () => model.initialize(), child: const Text('重试')),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (!state.isLoggedIn) {
|
||||
return SizedBox(
|
||||
height: 300,
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(FluentIcons.warning, size: 48, color: Colors.orange),
|
||||
const SizedBox(height: 16),
|
||||
const Text('您需要先登录才能授权', style: TextStyle(fontSize: 16)),
|
||||
const SizedBox(height: 24),
|
||||
FilledButton(onPressed: () => Navigator.of(context).pop(), child: const Text('前往登录')),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final displayDomain = state.domainName ?? state.domain ?? '未知应用';
|
||||
|
||||
return SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const SizedBox(height: 8),
|
||||
// Title
|
||||
RichText(
|
||||
textAlign: TextAlign.center,
|
||||
text: TextSpan(
|
||||
style: TextStyle(fontSize: 20, color: Colors.white.withValues(alpha: 0.95), fontFamily: 'Segoe UI'),
|
||||
children: [
|
||||
TextSpan(
|
||||
text: displayDomain,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
const TextSpan(text: ' 申请访问您的账户'),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
if (!state.isDomainTrusted)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.orange.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
border: Border.all(color: Colors.orange.withValues(alpha: 0.3)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(FluentIcons.warning, size: 12, color: Colors.orange),
|
||||
const SizedBox(width: 6),
|
||||
Text('未验证的应用', style: TextStyle(fontSize: 12, color: Colors.orange)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 2. User Account Info
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.white.withValues(alpha: 0.1)),
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ClipOval(
|
||||
child: SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: avatarUrl != null
|
||||
? CacheNetImage(url: avatarUrl, fit: BoxFit.cover)
|
||||
: const Icon(FluentIcons.contact, size: 24),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
userEmail.isNotEmpty ? userEmail : userName,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: Colors.white.withValues(alpha: 0.8),
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 32),
|
||||
|
||||
// 3. Permission Scope
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text('此操作将允许 $displayDomain:', style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500)),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
_buildPermissionItem(FluentIcons.contact_info, '访问您的公开资料', '包括用户名、头像'),
|
||||
|
||||
const SizedBox(height: 48),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPermissionItem(IconData icon, String title, String subtitle) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(icon, size: 20, color: Colors.blue),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title, style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500)),
|
||||
const SizedBox(height: 2),
|
||||
Text(subtitle, style: TextStyle(fontSize: 12, color: Colors.white.withValues(alpha: 0.6))),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _handleAuthorize(BuildContext context, WidgetRef ref, bool copyOnly) async {
|
||||
final provider = authUIModelProvider(callbackUrl: callbackUrl, stateParameter: stateParameter, nonce: nonce);
|
||||
final modelNotifier = ref.read(provider.notifier);
|
||||
final model = ref.read(provider);
|
||||
|
||||
// First, generate the code if not already generated
|
||||
if (model.code == null) {
|
||||
final success = await modelNotifier.generateCodeOnConfirm();
|
||||
if (!success) {
|
||||
if (context.mounted) {
|
||||
final currentState = ref.read(provider);
|
||||
await showToast(context, currentState.error ?? '生成授权码失败');
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final authUrl = modelNotifier.getAuthorizationUrl();
|
||||
if (authUrl == null) {
|
||||
if (context.mounted) {
|
||||
await showToast(context, '生成授权链接失败');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (copyOnly) {
|
||||
await modelNotifier.copyAuthorizationUrl();
|
||||
if (context.mounted) {
|
||||
await showToast(context, '授权链接已复制到剪贴板');
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
final launched = await launchUrlString(authUrl);
|
||||
if (!launched) {
|
||||
if (context.mounted) {
|
||||
await showToast(context, '打开浏览器失败,请复制链接手动访问');
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
await showToast(context, '打开浏览器失败: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
237
lib/ui/auth/auth_ui_model.dart
Normal file
237
lib/ui/auth/auth_ui_model.dart
Normal file
@@ -0,0 +1,237 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:starcitizen_doctor/common/utils/log.dart';
|
||||
import 'package:starcitizen_doctor/generated/proto/auth/auth.pb.dart';
|
||||
import 'package:starcitizen_doctor/provider/party_room.dart';
|
||||
import 'package:starcitizen_doctor/ui/party_room/party_room_ui_model.dart';
|
||||
|
||||
part 'auth_ui_model.freezed.dart';
|
||||
part 'auth_ui_model.g.dart';
|
||||
|
||||
@freezed
|
||||
sealed class AuthUIState with _$AuthUIState {
|
||||
const factory AuthUIState({
|
||||
@Default(false) bool isLoading,
|
||||
@Default(false) bool isLoggedIn,
|
||||
@Default(false) bool isWaitingForConnection,
|
||||
String? domain,
|
||||
String? callbackUrl,
|
||||
String? stateParameter,
|
||||
String? nonce,
|
||||
String? code,
|
||||
String? error,
|
||||
@Default(false) bool isDomainTrusted,
|
||||
String? domainName,
|
||||
}) = _AuthUIState;
|
||||
}
|
||||
|
||||
@riverpod
|
||||
class AuthUIModel extends _$AuthUIModel {
|
||||
@override
|
||||
AuthUIState build({String? callbackUrl, String? stateParameter, String? nonce}) {
|
||||
// Listen to party room connection and auth state changes
|
||||
ref.listen(partyRoomProvider, (previous, next) {
|
||||
// If we're waiting for connection and now connected, re-initialize
|
||||
if (state.isWaitingForConnection && next.client.isConnected && next.client.authClient != null) {
|
||||
dPrint('[AuthUI] Connection established, re-initializing...');
|
||||
Future.microtask(() => initialize());
|
||||
}
|
||||
|
||||
// If not logged in before and now logged in, re-initialize
|
||||
if (!state.isLoggedIn && previous?.auth.isLoggedIn == false && next.auth.isLoggedIn) {
|
||||
dPrint('[AuthUI] User logged in, re-initializing...');
|
||||
Future.microtask(() => initialize());
|
||||
}
|
||||
});
|
||||
|
||||
// Listen to party room UI model for login status changes
|
||||
ref.listen(partyRoomUIModelProvider, (previous, next) {
|
||||
// If was logging in and now finished (success or fail), re-check logic
|
||||
if (previous?.isLoggingIn == true && !next.isLoggingIn) {
|
||||
dPrint('[AuthUI] Login process finished, re-initializing...');
|
||||
Future.microtask(() => initialize());
|
||||
}
|
||||
});
|
||||
|
||||
return AuthUIState(callbackUrl: callbackUrl, stateParameter: stateParameter, nonce: nonce);
|
||||
}
|
||||
|
||||
Future<void> initialize() async {
|
||||
state = state.copyWith(isLoading: true, error: null, isWaitingForConnection: false);
|
||||
|
||||
try {
|
||||
// Check if domain and callbackUrl are provided
|
||||
|
||||
if (state.callbackUrl == null || state.callbackUrl!.isEmpty) {
|
||||
state = state.copyWith(isLoading: false, error: '缺少回调地址参数');
|
||||
return;
|
||||
}
|
||||
|
||||
if (state.stateParameter == null || state.stateParameter!.isEmpty) {
|
||||
state = state.copyWith(isLoading: false, error: '缺少 state 参数');
|
||||
return;
|
||||
}
|
||||
|
||||
// Extract domain from callbackUrl
|
||||
String? domain;
|
||||
try {
|
||||
final uri = Uri.parse(state.callbackUrl!);
|
||||
if (uri.host.isNotEmpty) {
|
||||
domain = uri.host;
|
||||
}
|
||||
} catch (e) {
|
||||
dPrint('Failed to parse callbackUrl: $e');
|
||||
}
|
||||
|
||||
if (domain == null || domain.isEmpty) {
|
||||
state = state.copyWith(isLoading: false, error: '无法从回调地址解析域名');
|
||||
return;
|
||||
}
|
||||
|
||||
// Update state with extracted domain
|
||||
state = state.copyWith(domain: domain);
|
||||
|
||||
// Get party room providers
|
||||
final partyRoom = ref.read(partyRoomProvider);
|
||||
final partyRoomUI = ref.read(partyRoomUIModelProvider);
|
||||
|
||||
// Check if connected to server
|
||||
if (!partyRoom.client.isConnected || partyRoom.client.authClient == null) {
|
||||
dPrint('[AuthUI] Server not connected, waiting for connection...');
|
||||
state = state.copyWith(isLoading: false, isWaitingForConnection: true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if user is logged in
|
||||
if (!partyRoom.auth.isLoggedIn) {
|
||||
// If still logging in process (auto-login after connect), keep waiting
|
||||
if (partyRoomUI.isLoggingIn) {
|
||||
dPrint('[AuthUI] Auto-login in progress, waiting...');
|
||||
state = state.copyWith(isLoading: false, isWaitingForConnection: true);
|
||||
return;
|
||||
}
|
||||
|
||||
state = state.copyWith(isLoading: false, isLoggedIn: false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check domain trust status
|
||||
final domainListResponse = await _getDomainList();
|
||||
bool isDomainTrusted = false;
|
||||
String? domainName;
|
||||
|
||||
if (domainListResponse != null) {
|
||||
final domainInfo = domainListResponse.domains
|
||||
.cast<
|
||||
JWTDomainInfo?
|
||||
>() // Cast to nullable to use firstWhere with orElse returning null if needed, though JWTDomainInfo is not nullable in proto usually
|
||||
.firstWhere((d) => d?.domain.toLowerCase() == state.domain!.toLowerCase(), orElse: () => null);
|
||||
|
||||
if (domainInfo != null && domainInfo.domain.isNotEmpty) {
|
||||
isDomainTrusted = true;
|
||||
domainName = domainInfo.name;
|
||||
}
|
||||
}
|
||||
|
||||
// Don't generate token yet - wait for user confirmation
|
||||
state = state.copyWith(
|
||||
isLoading: false,
|
||||
isLoggedIn: true,
|
||||
isDomainTrusted: isDomainTrusted,
|
||||
domainName: domainName,
|
||||
);
|
||||
} catch (e) {
|
||||
dPrint('Auth initialization error: $e');
|
||||
state = state.copyWith(isLoading: false, error: '初始化失败: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> generateCodeOnConfirm() async {
|
||||
// Only generate code if user is logged in and no previous error
|
||||
if (!state.isLoggedIn) {
|
||||
return false;
|
||||
}
|
||||
|
||||
state = state.copyWith(isLoading: true);
|
||||
|
||||
try {
|
||||
// Generate OIDC Auth Code
|
||||
final code = await _generateOIDCAuthCode();
|
||||
|
||||
if (code == null) {
|
||||
state = state.copyWith(isLoading: false, error: '生成授权码失败');
|
||||
return false;
|
||||
}
|
||||
|
||||
state = state.copyWith(isLoading: false, code: code);
|
||||
return true;
|
||||
} catch (e) {
|
||||
dPrint('Generate code on confirm error: $e');
|
||||
state = state.copyWith(isLoading: false, error: '生成授权码失败: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<GetJWTDomainListResponse?> _getDomainList() async {
|
||||
try {
|
||||
final partyRoom = ref.read(partyRoomProvider);
|
||||
final partyRoomNotifier = ref.read(partyRoomProvider.notifier);
|
||||
final client = partyRoom.client.authClient;
|
||||
if (client == null) return null;
|
||||
|
||||
final response = await client.getJWTDomainList(
|
||||
GetJWTDomainListRequest(),
|
||||
options: partyRoomNotifier.getAuthCallOptions(),
|
||||
);
|
||||
return response;
|
||||
} catch (e) {
|
||||
dPrint('Get domain list error: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> _generateOIDCAuthCode() async {
|
||||
try {
|
||||
final partyRoom = ref.read(partyRoomProvider);
|
||||
final partyRoomNotifier = ref.read(partyRoomProvider.notifier);
|
||||
final client = partyRoom.client.authClient;
|
||||
if (client == null || state.callbackUrl == null) return null;
|
||||
|
||||
final request = GenerateOIDCAuthCodeRequest(redirectUri: state.callbackUrl!, nonce: state.nonce ?? '');
|
||||
|
||||
final response = await client.generateOIDCAuthCode(request, options: partyRoomNotifier.getAuthCallOptions());
|
||||
return response.code;
|
||||
} catch (e) {
|
||||
dPrint('Generate OIDC Auth Code error: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
String? getAuthorizationUrl() {
|
||||
if (state.code == null || state.callbackUrl == null || state.stateParameter == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Build authorization URL
|
||||
// Using query parameters (?) to allow both server-side and client-side processing
|
||||
final uri = Uri.parse(state.callbackUrl!);
|
||||
|
||||
// Merge existing query parameters with new ones
|
||||
final newQueryParameters = Map<String, dynamic>.from(uri.queryParameters);
|
||||
newQueryParameters['code'] = state.code!;
|
||||
newQueryParameters['state'] = state.stateParameter!;
|
||||
|
||||
final authUri = uri.replace(queryParameters: newQueryParameters);
|
||||
return authUri.toString();
|
||||
}
|
||||
|
||||
Future<void> copyAuthorizationUrl() async {
|
||||
final url = getAuthorizationUrl();
|
||||
if (url != null) {
|
||||
await Clipboard.setData(ClipboardData(text: url));
|
||||
}
|
||||
}
|
||||
}
|
||||
295
lib/ui/auth/auth_ui_model.freezed.dart
Normal file
295
lib/ui/auth/auth_ui_model.freezed.dart
Normal file
@@ -0,0 +1,295 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// coverage:ignore-file
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
|
||||
|
||||
part of 'auth_ui_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// dart format off
|
||||
T _$identity<T>(T value) => value;
|
||||
/// @nodoc
|
||||
mixin _$AuthUIState {
|
||||
|
||||
bool get isLoading; bool get isLoggedIn; bool get isWaitingForConnection; String? get domain; String? get callbackUrl; String? get stateParameter; String? get nonce; String? get code; String? get error; bool get isDomainTrusted; String? get domainName;
|
||||
/// Create a copy of AuthUIState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
$AuthUIStateCopyWith<AuthUIState> get copyWith => _$AuthUIStateCopyWithImpl<AuthUIState>(this as AuthUIState, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is AuthUIState&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.isLoggedIn, isLoggedIn) || other.isLoggedIn == isLoggedIn)&&(identical(other.isWaitingForConnection, isWaitingForConnection) || other.isWaitingForConnection == isWaitingForConnection)&&(identical(other.domain, domain) || other.domain == domain)&&(identical(other.callbackUrl, callbackUrl) || other.callbackUrl == callbackUrl)&&(identical(other.stateParameter, stateParameter) || other.stateParameter == stateParameter)&&(identical(other.nonce, nonce) || other.nonce == nonce)&&(identical(other.code, code) || other.code == code)&&(identical(other.error, error) || other.error == error)&&(identical(other.isDomainTrusted, isDomainTrusted) || other.isDomainTrusted == isDomainTrusted)&&(identical(other.domainName, domainName) || other.domainName == domainName));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,isLoading,isLoggedIn,isWaitingForConnection,domain,callbackUrl,stateParameter,nonce,code,error,isDomainTrusted,domainName);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'AuthUIState(isLoading: $isLoading, isLoggedIn: $isLoggedIn, isWaitingForConnection: $isWaitingForConnection, domain: $domain, callbackUrl: $callbackUrl, stateParameter: $stateParameter, nonce: $nonce, code: $code, error: $error, isDomainTrusted: $isDomainTrusted, domainName: $domainName)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class $AuthUIStateCopyWith<$Res> {
|
||||
factory $AuthUIStateCopyWith(AuthUIState value, $Res Function(AuthUIState) _then) = _$AuthUIStateCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
bool isLoading, bool isLoggedIn, bool isWaitingForConnection, String? domain, String? callbackUrl, String? stateParameter, String? nonce, String? code, String? error, bool isDomainTrusted, String? domainName
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class _$AuthUIStateCopyWithImpl<$Res>
|
||||
implements $AuthUIStateCopyWith<$Res> {
|
||||
_$AuthUIStateCopyWithImpl(this._self, this._then);
|
||||
|
||||
final AuthUIState _self;
|
||||
final $Res Function(AuthUIState) _then;
|
||||
|
||||
/// Create a copy of AuthUIState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? isLoading = null,Object? isLoggedIn = null,Object? isWaitingForConnection = null,Object? domain = freezed,Object? callbackUrl = freezed,Object? stateParameter = freezed,Object? nonce = freezed,Object? code = freezed,Object? error = freezed,Object? isDomainTrusted = null,Object? domainName = freezed,}) {
|
||||
return _then(_self.copyWith(
|
||||
isLoading: null == isLoading ? _self.isLoading : isLoading // ignore: cast_nullable_to_non_nullable
|
||||
as bool,isLoggedIn: null == isLoggedIn ? _self.isLoggedIn : isLoggedIn // ignore: cast_nullable_to_non_nullable
|
||||
as bool,isWaitingForConnection: null == isWaitingForConnection ? _self.isWaitingForConnection : isWaitingForConnection // ignore: cast_nullable_to_non_nullable
|
||||
as bool,domain: freezed == domain ? _self.domain : domain // ignore: cast_nullable_to_non_nullable
|
||||
as String?,callbackUrl: freezed == callbackUrl ? _self.callbackUrl : callbackUrl // ignore: cast_nullable_to_non_nullable
|
||||
as String?,stateParameter: freezed == stateParameter ? _self.stateParameter : stateParameter // ignore: cast_nullable_to_non_nullable
|
||||
as String?,nonce: freezed == nonce ? _self.nonce : nonce // ignore: cast_nullable_to_non_nullable
|
||||
as String?,code: freezed == code ? _self.code : code // ignore: cast_nullable_to_non_nullable
|
||||
as String?,error: freezed == error ? _self.error : error // ignore: cast_nullable_to_non_nullable
|
||||
as String?,isDomainTrusted: null == isDomainTrusted ? _self.isDomainTrusted : isDomainTrusted // ignore: cast_nullable_to_non_nullable
|
||||
as bool,domainName: freezed == domainName ? _self.domainName : domainName // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [AuthUIState].
|
||||
extension AuthUIStatePatterns on AuthUIState {
|
||||
/// A variant of `map` that fallback to returning `orElse`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _AuthUIState value)? $default,{required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _AuthUIState() when $default != null:
|
||||
return $default(_that);case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
}
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// Callbacks receives the raw object, upcasted.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case final Subclass2 value:
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _AuthUIState value) $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _AuthUIState():
|
||||
return $default(_that);}
|
||||
}
|
||||
/// A variant of `map` that fallback to returning `null`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _AuthUIState value)? $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _AuthUIState() when $default != null:
|
||||
return $default(_that);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
/// A variant of `when` that fallback to an `orElse` callback.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( bool isLoading, bool isLoggedIn, bool isWaitingForConnection, String? domain, String? callbackUrl, String? stateParameter, String? nonce, String? code, String? error, bool isDomainTrusted, String? domainName)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _AuthUIState() when $default != null:
|
||||
return $default(_that.isLoading,_that.isLoggedIn,_that.isWaitingForConnection,_that.domain,_that.callbackUrl,_that.stateParameter,_that.nonce,_that.code,_that.error,_that.isDomainTrusted,_that.domainName);case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
}
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// As opposed to `map`, this offers destructuring.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case Subclass2(:final field2):
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( bool isLoading, bool isLoggedIn, bool isWaitingForConnection, String? domain, String? callbackUrl, String? stateParameter, String? nonce, String? code, String? error, bool isDomainTrusted, String? domainName) $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _AuthUIState():
|
||||
return $default(_that.isLoading,_that.isLoggedIn,_that.isWaitingForConnection,_that.domain,_that.callbackUrl,_that.stateParameter,_that.nonce,_that.code,_that.error,_that.isDomainTrusted,_that.domainName);}
|
||||
}
|
||||
/// A variant of `when` that fallback to returning `null`
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( bool isLoading, bool isLoggedIn, bool isWaitingForConnection, String? domain, String? callbackUrl, String? stateParameter, String? nonce, String? code, String? error, bool isDomainTrusted, String? domainName)? $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _AuthUIState() when $default != null:
|
||||
return $default(_that.isLoading,_that.isLoggedIn,_that.isWaitingForConnection,_that.domain,_that.callbackUrl,_that.stateParameter,_that.nonce,_that.code,_that.error,_that.isDomainTrusted,_that.domainName);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _AuthUIState implements AuthUIState {
|
||||
const _AuthUIState({this.isLoading = false, this.isLoggedIn = false, this.isWaitingForConnection = false, this.domain, this.callbackUrl, this.stateParameter, this.nonce, this.code, this.error, this.isDomainTrusted = false, this.domainName});
|
||||
|
||||
|
||||
@override@JsonKey() final bool isLoading;
|
||||
@override@JsonKey() final bool isLoggedIn;
|
||||
@override@JsonKey() final bool isWaitingForConnection;
|
||||
@override final String? domain;
|
||||
@override final String? callbackUrl;
|
||||
@override final String? stateParameter;
|
||||
@override final String? nonce;
|
||||
@override final String? code;
|
||||
@override final String? error;
|
||||
@override@JsonKey() final bool isDomainTrusted;
|
||||
@override final String? domainName;
|
||||
|
||||
/// Create a copy of AuthUIState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$AuthUIStateCopyWith<_AuthUIState> get copyWith => __$AuthUIStateCopyWithImpl<_AuthUIState>(this, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _AuthUIState&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.isLoggedIn, isLoggedIn) || other.isLoggedIn == isLoggedIn)&&(identical(other.isWaitingForConnection, isWaitingForConnection) || other.isWaitingForConnection == isWaitingForConnection)&&(identical(other.domain, domain) || other.domain == domain)&&(identical(other.callbackUrl, callbackUrl) || other.callbackUrl == callbackUrl)&&(identical(other.stateParameter, stateParameter) || other.stateParameter == stateParameter)&&(identical(other.nonce, nonce) || other.nonce == nonce)&&(identical(other.code, code) || other.code == code)&&(identical(other.error, error) || other.error == error)&&(identical(other.isDomainTrusted, isDomainTrusted) || other.isDomainTrusted == isDomainTrusted)&&(identical(other.domainName, domainName) || other.domainName == domainName));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,isLoading,isLoggedIn,isWaitingForConnection,domain,callbackUrl,stateParameter,nonce,code,error,isDomainTrusted,domainName);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'AuthUIState(isLoading: $isLoading, isLoggedIn: $isLoggedIn, isWaitingForConnection: $isWaitingForConnection, domain: $domain, callbackUrl: $callbackUrl, stateParameter: $stateParameter, nonce: $nonce, code: $code, error: $error, isDomainTrusted: $isDomainTrusted, domainName: $domainName)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$AuthUIStateCopyWith<$Res> implements $AuthUIStateCopyWith<$Res> {
|
||||
factory _$AuthUIStateCopyWith(_AuthUIState value, $Res Function(_AuthUIState) _then) = __$AuthUIStateCopyWithImpl;
|
||||
@override @useResult
|
||||
$Res call({
|
||||
bool isLoading, bool isLoggedIn, bool isWaitingForConnection, String? domain, String? callbackUrl, String? stateParameter, String? nonce, String? code, String? error, bool isDomainTrusted, String? domainName
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$AuthUIStateCopyWithImpl<$Res>
|
||||
implements _$AuthUIStateCopyWith<$Res> {
|
||||
__$AuthUIStateCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _AuthUIState _self;
|
||||
final $Res Function(_AuthUIState) _then;
|
||||
|
||||
/// Create a copy of AuthUIState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? isLoading = null,Object? isLoggedIn = null,Object? isWaitingForConnection = null,Object? domain = freezed,Object? callbackUrl = freezed,Object? stateParameter = freezed,Object? nonce = freezed,Object? code = freezed,Object? error = freezed,Object? isDomainTrusted = null,Object? domainName = freezed,}) {
|
||||
return _then(_AuthUIState(
|
||||
isLoading: null == isLoading ? _self.isLoading : isLoading // ignore: cast_nullable_to_non_nullable
|
||||
as bool,isLoggedIn: null == isLoggedIn ? _self.isLoggedIn : isLoggedIn // ignore: cast_nullable_to_non_nullable
|
||||
as bool,isWaitingForConnection: null == isWaitingForConnection ? _self.isWaitingForConnection : isWaitingForConnection // ignore: cast_nullable_to_non_nullable
|
||||
as bool,domain: freezed == domain ? _self.domain : domain // ignore: cast_nullable_to_non_nullable
|
||||
as String?,callbackUrl: freezed == callbackUrl ? _self.callbackUrl : callbackUrl // ignore: cast_nullable_to_non_nullable
|
||||
as String?,stateParameter: freezed == stateParameter ? _self.stateParameter : stateParameter // ignore: cast_nullable_to_non_nullable
|
||||
as String?,nonce: freezed == nonce ? _self.nonce : nonce // ignore: cast_nullable_to_non_nullable
|
||||
as String?,code: freezed == code ? _self.code : code // ignore: cast_nullable_to_non_nullable
|
||||
as String?,error: freezed == error ? _self.error : error // ignore: cast_nullable_to_non_nullable
|
||||
as String?,isDomainTrusted: null == isDomainTrusted ? _self.isDomainTrusted : isDomainTrusted // ignore: cast_nullable_to_non_nullable
|
||||
as bool,domainName: freezed == domainName ? _self.domainName : domainName // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// dart format on
|
||||
131
lib/ui/auth/auth_ui_model.g.dart
Normal file
131
lib/ui/auth/auth_ui_model.g.dart
Normal file
@@ -0,0 +1,131 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'auth_ui_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(AuthUIModel)
|
||||
const authUIModelProvider = AuthUIModelFamily._();
|
||||
|
||||
final class AuthUIModelProvider
|
||||
extends $NotifierProvider<AuthUIModel, AuthUIState> {
|
||||
const AuthUIModelProvider._({
|
||||
required AuthUIModelFamily super.from,
|
||||
required ({String? callbackUrl, String? stateParameter, String? nonce})
|
||||
super.argument,
|
||||
}) : super(
|
||||
retry: null,
|
||||
name: r'authUIModelProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$authUIModelHash();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return r'authUIModelProvider'
|
||||
''
|
||||
'$argument';
|
||||
}
|
||||
|
||||
@$internal
|
||||
@override
|
||||
AuthUIModel create() => AuthUIModel();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(AuthUIState value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<AuthUIState>(value),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is AuthUIModelProvider && other.argument == argument;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return argument.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
String _$authUIModelHash() => r'cef2bc3fecb2c52e507fa24bc352b4553d918a38';
|
||||
|
||||
final class AuthUIModelFamily extends $Family
|
||||
with
|
||||
$ClassFamilyOverride<
|
||||
AuthUIModel,
|
||||
AuthUIState,
|
||||
AuthUIState,
|
||||
AuthUIState,
|
||||
({String? callbackUrl, String? stateParameter, String? nonce})
|
||||
> {
|
||||
const AuthUIModelFamily._()
|
||||
: super(
|
||||
retry: null,
|
||||
name: r'authUIModelProvider',
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
isAutoDispose: true,
|
||||
);
|
||||
|
||||
AuthUIModelProvider call({
|
||||
String? callbackUrl,
|
||||
String? stateParameter,
|
||||
String? nonce,
|
||||
}) => AuthUIModelProvider._(
|
||||
argument: (
|
||||
callbackUrl: callbackUrl,
|
||||
stateParameter: stateParameter,
|
||||
nonce: nonce,
|
||||
),
|
||||
from: this,
|
||||
);
|
||||
|
||||
@override
|
||||
String toString() => r'authUIModelProvider';
|
||||
}
|
||||
|
||||
abstract class _$AuthUIModel extends $Notifier<AuthUIState> {
|
||||
late final _$args =
|
||||
ref.$arg
|
||||
as ({String? callbackUrl, String? stateParameter, String? nonce});
|
||||
String? get callbackUrl => _$args.callbackUrl;
|
||||
String? get stateParameter => _$args.stateParameter;
|
||||
String? get nonce => _$args.nonce;
|
||||
|
||||
AuthUIState build({
|
||||
String? callbackUrl,
|
||||
String? stateParameter,
|
||||
String? nonce,
|
||||
});
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final created = build(
|
||||
callbackUrl: _$args.callbackUrl,
|
||||
stateParameter: _$args.stateParameter,
|
||||
nonce: _$args.nonce,
|
||||
);
|
||||
final ref = this.ref as $Ref<AuthUIState, AuthUIState>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<AuthUIState, AuthUIState>,
|
||||
AuthUIState,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleValue(ref, created);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user