forked from ReiMerc/skantravels
Implement registering
This commit is contained in:
parent
debbddd05b
commit
eef47f6ee4
@ -1,6 +1,4 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'register.dart';
|
||||
import 'api.dart' as api;
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'login.dart';
|
||||
import 'api.dart' as api;
|
||||
|
||||
class RegisterPage extends StatefulWidget {
|
||||
const RegisterPage({super.key, required this.title});
|
||||
@ -11,6 +12,25 @@ class RegisterPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _RegisterPageState extends State<RegisterPage> {
|
||||
final usernameInput = TextEditingController();
|
||||
final emailInput = TextEditingController();
|
||||
final passwordInput = TextEditingController();
|
||||
|
||||
Future<void> _register() async {
|
||||
final result = await api.request(context, api.ApiService.auth, 'POST', '/api/Users', {
|
||||
'username': usernameInput.text,
|
||||
'email': emailInput.text,
|
||||
'password': passwordInput.text,
|
||||
});
|
||||
|
||||
if (result == null) return;
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Successfully registered, please login')));
|
||||
Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => const LoginPage(title: 'Log ind')));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@ -25,15 +45,15 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
children: [
|
||||
const SizedBox(height: 80),
|
||||
const Text('Brugernavn'),
|
||||
const TextField(),
|
||||
TextField(controller: usernameInput),
|
||||
const SizedBox(height: 30),
|
||||
const Text('Email'),
|
||||
const TextField(),
|
||||
TextField(controller: emailInput),
|
||||
const SizedBox(height: 30),
|
||||
const Text('Password'),
|
||||
const TextField(obscureText: true, enableSuggestions: false, autocorrect: false),
|
||||
TextField(controller: passwordInput, obscureText: true, enableSuggestions: false, autocorrect: false),
|
||||
const SizedBox(height: 30),
|
||||
ElevatedButton(child: const Text('Registrer'), onPressed: () => Navigator.pop(context)),
|
||||
ElevatedButton(onPressed: _register, child: const Text('Registrer')),
|
||||
const SizedBox(height: 10),
|
||||
TextButton(
|
||||
child: const Text('Log ind'),
|
||||
@ -45,4 +65,12 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
usernameInput.dispose();
|
||||
emailInput.dispose();
|
||||
passwordInput.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user