2024-05-18 16:56:32 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-09-07 09:45:44 +00:00
|
|
|
import 'package:gap/gap.dart';
|
2024-05-18 16:56:32 +00:00
|
|
|
import 'package:get/get.dart';
|
2024-05-19 16:08:20 +00:00
|
|
|
import 'package:solian/exts.dart';
|
2024-05-18 16:56:32 +00:00
|
|
|
import 'package:solian/services.dart';
|
2024-09-15 15:32:15 +00:00
|
|
|
import 'package:solian/widgets/sized_container.dart';
|
2024-09-19 12:34:04 +00:00
|
|
|
import 'package:url_launcher/url_launcher_string.dart';
|
2024-05-18 16:56:32 +00:00
|
|
|
|
2024-09-15 15:32:15 +00:00
|
|
|
class SignUpScreen extends StatefulWidget {
|
|
|
|
const SignUpScreen({super.key});
|
2024-05-18 16:56:32 +00:00
|
|
|
|
|
|
|
@override
|
2024-09-15 15:32:15 +00:00
|
|
|
State<SignUpScreen> createState() => _SignUpScreenState();
|
2024-05-18 16:56:32 +00:00
|
|
|
}
|
|
|
|
|
2024-09-15 15:32:15 +00:00
|
|
|
class _SignUpScreenState extends State<SignUpScreen> {
|
2024-05-18 16:56:32 +00:00
|
|
|
final _emailController = TextEditingController();
|
|
|
|
final _usernameController = TextEditingController();
|
|
|
|
final _nicknameController = TextEditingController();
|
|
|
|
final _passwordController = TextEditingController();
|
|
|
|
|
2024-09-19 12:34:04 +00:00
|
|
|
void _performAction(BuildContext context) async {
|
2024-05-18 16:56:32 +00:00
|
|
|
final email = _emailController.value.text;
|
|
|
|
final username = _usernameController.value.text;
|
2024-07-02 15:26:17 +00:00
|
|
|
final nickname = _nicknameController.value.text;
|
2024-05-18 16:56:32 +00:00
|
|
|
final password = _passwordController.value.text;
|
|
|
|
if (email.isEmpty ||
|
|
|
|
username.isEmpty ||
|
|
|
|
nickname.isEmpty ||
|
|
|
|
password.isEmpty) return;
|
|
|
|
|
2024-09-16 03:57:16 +00:00
|
|
|
final client = await ServiceFinder.configureClient('auth');
|
2024-06-06 12:49:18 +00:00
|
|
|
|
2024-07-16 11:46:53 +00:00
|
|
|
final resp = await client.post('/users', {
|
2024-05-18 16:56:32 +00:00
|
|
|
'name': username,
|
|
|
|
'nick': nickname,
|
|
|
|
'email': email,
|
|
|
|
'password': password,
|
|
|
|
});
|
|
|
|
|
2024-05-19 12:30:50 +00:00
|
|
|
if (resp.statusCode == 200) {
|
2024-05-18 16:56:32 +00:00
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) {
|
|
|
|
return AlertDialog(
|
|
|
|
title: Text('signupDone'.tr),
|
|
|
|
content: Text('signupDoneCaption'.tr),
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
2024-07-02 15:26:17 +00:00
|
|
|
child: Text('okay'.tr),
|
2024-05-18 16:56:32 +00:00
|
|
|
onPressed: () => Navigator.pop(context),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
).then((_) {
|
2024-07-02 15:26:17 +00:00
|
|
|
Navigator.pop(context);
|
2024-05-18 16:56:32 +00:00
|
|
|
});
|
|
|
|
} else {
|
2024-05-19 16:08:20 +00:00
|
|
|
context.showErrorDialog(resp.bodyString);
|
2024-05-18 16:56:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-19 12:34:04 +00:00
|
|
|
bool _isTermAccepted = false;
|
|
|
|
|
2024-05-18 16:56:32 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-10-06 15:06:33 +00:00
|
|
|
return CenteredContainer(
|
|
|
|
maxWidth: 360,
|
|
|
|
child: ListView(
|
|
|
|
shrinkWrap: true,
|
|
|
|
children: [
|
|
|
|
Align(
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
|
|
|
child: Image.asset('assets/logo.png', width: 64, height: 64),
|
|
|
|
).paddingOnly(bottom: 8, left: 4),
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
'signupGreeting'.tr,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 28,
|
|
|
|
fontWeight: FontWeight.w900,
|
2024-09-19 12:34:04 +00:00
|
|
|
),
|
2024-10-06 15:06:33 +00:00
|
|
|
).paddingOnly(left: 4, bottom: 16),
|
|
|
|
TextField(
|
|
|
|
autocorrect: false,
|
|
|
|
enableSuggestions: false,
|
|
|
|
controller: _usernameController,
|
|
|
|
autofillHints: const [AutofillHints.username],
|
|
|
|
decoration: InputDecoration(
|
|
|
|
isDense: true,
|
|
|
|
border: const OutlineInputBorder(),
|
|
|
|
labelText: 'username'.tr,
|
2024-09-15 15:32:15 +00:00
|
|
|
),
|
2024-10-06 15:06:33 +00:00
|
|
|
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
|
|
|
|
),
|
|
|
|
const Gap(12),
|
|
|
|
TextField(
|
|
|
|
autocorrect: false,
|
|
|
|
enableSuggestions: false,
|
|
|
|
controller: _nicknameController,
|
|
|
|
autofillHints: const [AutofillHints.nickname],
|
|
|
|
decoration: InputDecoration(
|
|
|
|
isDense: true,
|
|
|
|
border: const OutlineInputBorder(),
|
|
|
|
labelText: 'nickname'.tr,
|
2024-09-15 15:32:15 +00:00
|
|
|
),
|
2024-10-06 15:06:33 +00:00
|
|
|
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
|
|
|
|
),
|
|
|
|
const Gap(12),
|
|
|
|
TextField(
|
|
|
|
autocorrect: false,
|
|
|
|
enableSuggestions: false,
|
|
|
|
controller: _emailController,
|
|
|
|
autofillHints: const [AutofillHints.email],
|
|
|
|
decoration: InputDecoration(
|
|
|
|
isDense: true,
|
|
|
|
border: const OutlineInputBorder(),
|
|
|
|
labelText: 'email'.tr,
|
2024-09-15 15:32:15 +00:00
|
|
|
),
|
2024-10-06 15:06:33 +00:00
|
|
|
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
|
|
|
|
),
|
|
|
|
const Gap(12),
|
|
|
|
TextField(
|
|
|
|
obscureText: true,
|
|
|
|
autocorrect: false,
|
|
|
|
enableSuggestions: false,
|
|
|
|
autofillHints: const [AutofillHints.password],
|
|
|
|
controller: _passwordController,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
isDense: true,
|
|
|
|
border: const OutlineInputBorder(),
|
|
|
|
labelText: 'password'.tr,
|
2024-09-19 12:34:04 +00:00
|
|
|
),
|
2024-10-06 15:06:33 +00:00
|
|
|
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
|
|
|
|
onSubmitted: (_) => _performAction(context),
|
|
|
|
),
|
|
|
|
const Gap(8),
|
|
|
|
CheckboxListTile(
|
|
|
|
value: _isTermAccepted,
|
|
|
|
title: Text(
|
|
|
|
'termAccept'.tr,
|
|
|
|
style: const TextStyle(height: 1.2),
|
|
|
|
).paddingOnly(bottom: 4),
|
|
|
|
shape: const RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.all(
|
|
|
|
Radius.circular(8),
|
2024-09-19 12:34:04 +00:00
|
|
|
),
|
2024-10-06 15:06:33 +00:00
|
|
|
),
|
|
|
|
subtitle: RichText(
|
|
|
|
text: TextSpan(
|
|
|
|
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.colorScheme
|
|
|
|
.onSurface
|
|
|
|
.withOpacity(0.75),
|
|
|
|
),
|
|
|
|
children: [
|
|
|
|
TextSpan(text: 'termAcceptDesc'.tr),
|
|
|
|
WidgetSpan(
|
|
|
|
child: Material(
|
|
|
|
color: Colors.transparent,
|
|
|
|
child: InkWell(
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Text('termAcceptLink'.tr),
|
|
|
|
const Gap(4),
|
|
|
|
const Icon(Icons.launch, size: 14),
|
|
|
|
],
|
2024-09-19 12:34:04 +00:00
|
|
|
),
|
2024-10-06 15:06:33 +00:00
|
|
|
onTap: () {
|
|
|
|
launchUrlString('https://solsynth.dev/terms');
|
|
|
|
},
|
2024-09-19 12:34:04 +00:00
|
|
|
),
|
|
|
|
),
|
2024-10-06 15:06:33 +00:00
|
|
|
),
|
|
|
|
],
|
2024-09-19 12:34:04 +00:00
|
|
|
),
|
2024-09-15 15:32:15 +00:00
|
|
|
),
|
2024-10-06 15:06:33 +00:00
|
|
|
onChanged: (value) {
|
|
|
|
setState(() => _isTermAccepted = value ?? false);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
const Gap(16),
|
|
|
|
Align(
|
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
child: TextButton(
|
|
|
|
onPressed:
|
|
|
|
!_isTermAccepted ? null : () => _performAction(context),
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Text('next'.tr),
|
|
|
|
const Icon(Icons.chevron_right),
|
|
|
|
],
|
2024-09-15 15:32:15 +00:00
|
|
|
),
|
2024-10-06 15:06:33 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
2024-09-19 12:34:04 +00:00
|
|
|
).paddingAll(24),
|
2024-05-18 16:56:32 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|