mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-09 07:28:14 -07:00
Init repo
This commit is contained in:
commit
764b6034e3
566 changed files with 212335 additions and 0 deletions
119
lib/screens/settings/quick_connect_window.dart
Normal file
119
lib/screens/settings/quick_connect_window.dart
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
import 'package:fladder/providers/user_provider.dart';
|
||||
import 'package:fladder/screens/login/widgets/login_icon.dart';
|
||||
import 'package:fladder/screens/shared/outlined_text_field.dart';
|
||||
import 'package:fladder/util/list_padding.dart';
|
||||
import 'package:fladder/util/localization_helper.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
Future<void> openQuickConnectDialog(
|
||||
BuildContext context,
|
||||
) async {
|
||||
return showDialog(context: context, builder: (context) => QuickConnectDialog());
|
||||
}
|
||||
|
||||
class QuickConnectDialog extends ConsumerStatefulWidget {
|
||||
const QuickConnectDialog({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<ConsumerStatefulWidget> createState() => _QuickConnectDialogState();
|
||||
}
|
||||
|
||||
class _QuickConnectDialogState extends ConsumerState<QuickConnectDialog> {
|
||||
final controller = TextEditingController();
|
||||
bool loading = false;
|
||||
String? error;
|
||||
String? success;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final user = ref.watch(userProvider);
|
||||
return AlertDialog.adaptive(
|
||||
title: Text(context.localized.quickConnectTitle),
|
||||
scrollable: true,
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(context.localized.quickConnectAction),
|
||||
if (user != null) SizedBox(child: LoginIcon(user: user)),
|
||||
Flexible(
|
||||
child: OutlinedTextField(
|
||||
label: context.localized.code,
|
||||
controller: controller,
|
||||
keyboardType: TextInputType.number,
|
||||
onChanged: (value) {
|
||||
if (value.isNotEmpty) {
|
||||
setState(() {
|
||||
error = null;
|
||||
success = null;
|
||||
});
|
||||
}
|
||||
},
|
||||
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
|
||||
),
|
||||
),
|
||||
AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 250),
|
||||
child: error != null || success != null
|
||||
? Card(
|
||||
key: Key(context.localized.error),
|
||||
color: success == null
|
||||
? Theme.of(context).colorScheme.errorContainer
|
||||
: Theme.of(context).colorScheme.surfaceContainer,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
success ?? error ?? "",
|
||||
style: TextStyle(
|
||||
color: success == null
|
||||
? Theme.of(context).colorScheme.onErrorContainer
|
||||
: Theme.of(context).colorScheme.onSurface),
|
||||
),
|
||||
),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: loading
|
||||
? null
|
||||
: () async {
|
||||
setState(() {
|
||||
error = null;
|
||||
loading = true;
|
||||
});
|
||||
final response = await ref.read(userProvider.notifier).quickConnect(controller.text);
|
||||
if (response.isSuccessful) {
|
||||
setState(
|
||||
() {
|
||||
error = null;
|
||||
success = context.localized.loggedIn;
|
||||
},
|
||||
);
|
||||
await Future.delayed(Duration(seconds: 2));
|
||||
Navigator.of(context).pop();
|
||||
} else {
|
||||
if (controller.text.isEmpty) {
|
||||
error = context.localized.quickConnectInputACode;
|
||||
} else {
|
||||
error = context.localized.quickConnectWrongCode;
|
||||
}
|
||||
}
|
||||
loading = false;
|
||||
setState(
|
||||
() {},
|
||||
);
|
||||
controller.text = "";
|
||||
},
|
||||
child: loading
|
||||
? SizedBox.square(
|
||||
child: CircularProgressIndicator(),
|
||||
dimension: 16.0,
|
||||
)
|
||||
: Text(context.localized.login),
|
||||
)
|
||||
].addInBetween(const SizedBox(height: 16)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue