Add manual auth screen
This commit is contained in:
85
moneymgr_mobile/lib/routes/login/manual_auth_screen.dart
Normal file
85
moneymgr_mobile/lib/routes/login/manual_auth_screen.dart
Normal file
@ -0,0 +1,85 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gutter/flutter_gutter.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:moneymgr_mobile/routes/login/base_auth_page.dart';
|
||||
import 'package:moneymgr_mobile/services/api/api_token.dart';
|
||||
import 'package:moneymgr_mobile/services/auth_state.dart';
|
||||
import 'package:moneymgr_mobile/utils/extensions.dart';
|
||||
import 'package:moneymgr_mobile/widgets/app_button.dart';
|
||||
|
||||
class ManualAuthScreen extends HookConsumerWidget {
|
||||
const ManualAuthScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
var apiUrlController = useTextEditingController();
|
||||
var tokenIdController = useTextEditingController();
|
||||
var tokenValueController = useTextEditingController();
|
||||
|
||||
Future<void> onSubmit() async {
|
||||
try {
|
||||
await ref
|
||||
.read(currentAuthStateProvider.notifier)
|
||||
.setAuthToken(
|
||||
ApiToken(
|
||||
apiUrl: apiUrlController.text,
|
||||
tokenId: int.tryParse(tokenIdController.text) ?? 1,
|
||||
tokenValue: tokenValueController.text,
|
||||
),
|
||||
);
|
||||
} catch (e, s) {
|
||||
Logger.root.severe("Failed to authenticate user! $e $s");
|
||||
if (context.mounted) {
|
||||
context.showTextSnackBar("Failed to authenticate user! $e");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return BaseAuthPage(
|
||||
title: "Manual authentication",
|
||||
showSettings: false,
|
||||
children: [
|
||||
Gutter(scaleFactor: 3),
|
||||
Text(
|
||||
"On this screen you can manually enter authentication information.",
|
||||
),
|
||||
Gutter(),
|
||||
TextField(
|
||||
controller: apiUrlController,
|
||||
keyboardType: TextInputType.url,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'API URL',
|
||||
helperText:
|
||||
"This URL has usually this format: http://moneymgr.corp.com/api",
|
||||
),
|
||||
textInputAction: TextInputAction.next,
|
||||
),
|
||||
Gutter(),
|
||||
TextField(
|
||||
controller: tokenIdController,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Token ID',
|
||||
helperText: "The ID of the token",
|
||||
),
|
||||
textInputAction: TextInputAction.next,
|
||||
),
|
||||
Gutter(),
|
||||
TextField(
|
||||
controller: tokenIdController,
|
||||
keyboardType: TextInputType.text,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Token value',
|
||||
helperText: "The value of the token itself",
|
||||
),
|
||||
textInputAction: TextInputAction.done,
|
||||
),
|
||||
Gutter(),
|
||||
AppButton(onPressed: onSubmit, label: "Submit"),
|
||||
Gutter(scaleFactor: 3),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user