Better form and remove squares
All checks were successful
ci/woodpecker/push/build Pipeline was successful

Signed-off-by: Nikolai Rodionov <allanger@posteo.de>
This commit is contained in:
Nikolai Rodionov
2026-05-28 23:58:08 +02:00
parent aeb5269fc5
commit 84d65786bf
9 changed files with 215 additions and 122 deletions

View File

@@ -63,9 +63,13 @@ class AuthorizationController extends AsyncNotifier<AuthState> {
final accountsGrpc = ref.read(publicAccountsGrpcProvider); final accountsGrpc = ref.read(publicAccountsGrpcProvider);
final tokenCtrl = ref.read(tokensControllerProvider.notifier); final tokenCtrl = ref.read(tokensControllerProvider.notifier);
final response = await accountsGrpc.signIn(form.toProto()); try {
await tokenCtrl.writeTokenPair(Tokens.fromProto(response.tokenPair)); final response = await accountsGrpc.signIn(form.toProto());
return state.value!.copyWith(isAuthorized: true); await tokenCtrl.writeTokenPair(Tokens.fromProto(response.tokenPair));
return state.value!.copyWith(isAuthorized: true);
} catch (e) {
rethrow;
}
}); });
} }

View File

@@ -12,17 +12,22 @@ class AuthorizationPage extends ConsumerStatefulWidget {
ConsumerState<AuthorizationPage> createState() => _AuthorizationPage(); ConsumerState<AuthorizationPage> createState() => _AuthorizationPage();
} }
enum AuthMode { login, signup }
class _AuthorizationPage extends ConsumerState<AuthorizationPage> { class _AuthorizationPage extends ConsumerState<AuthorizationPage> {
bool showSignUp = false;
void toggleAuth() {
setState(() {
showSignUp = !showSignUp;
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final state = ref.watch(authorizationControllerProvider);
final isLoading = state.isLoading;
final authState = state.value;
return LayoutBuilder( return LayoutBuilder(
builder: (context, constraints) { builder: (context, constraints) {
final showDecoration = constraints.maxWidth > 1000; final showDecoration = constraints.maxWidth > 1000;
return Scaffold( return Scaffold(
body: Row( body: Row(
children: [ children: [
@@ -37,10 +42,14 @@ class _AuthorizationPage extends ConsumerState<AuthorizationPage> {
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
if (authState!.mode == AuthMode.login) Offstage(
LoginForm() offstage: showSignUp == true,
else child: LoginForm(toggleAuth: toggleAuth),
RegisterForm(), ),
Offstage(
offstage: showSignUp != true,
child: RegisterForm(toggleAuth: toggleAuth),
),
], ],
), ),
), ),
@@ -49,13 +58,6 @@ class _AuthorizationPage extends ConsumerState<AuthorizationPage> {
// ✅ only show decoration if width > 400 // ✅ only show decoration if width > 400
if (showDecoration) Expanded(flex: 3, child: AuthDecoration()), if (showDecoration) Expanded(flex: 3, child: AuthDecoration()),
if (isLoading)
Positioned.fill(
child: Container(
color: Colors.black.withValues(alpha: 0.2),
child: const Center(child: CircularProgressIndicator()),
),
),
], ],
), ),
); );

View File

@@ -1,89 +1,91 @@
import 'dart:math' as math;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:softplayer_web/shared/ui/colors/light_mode.dart'; import 'package:softplayer_web/shared/ui/colors/light_mode.dart';
class AuthDecoration extends StatelessWidget { class AuthDecoration extends StatelessWidget {
final double spacing; const AuthDecoration({super.key});
final Color color;
const AuthDecoration({
super.key,
this.spacing = 24,
this.color = Colors.blue,
});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return LayoutBuilder( return Container(
builder: (context, constraints) { color: LightModeColors.backgroundElevated,
return Container( child: FractionallySizedBox(
color: LightModeColors.backgroundElevated, alignment: Alignment.centerLeft,
child: FractionallySizedBox( child: const CustomPaint(
widthFactor: 0.3, painter: _GradientPainter(),
alignment: Alignment.centerLeft, child: SizedBox.expand(),
child: CustomPaint( ),
painter: _GridPainter(spacing: spacing, color: color), ),
child: const SizedBox.expand(),
),
),
);
},
); );
} }
} }
// todo: Some AI generated shite, that doesn't work class _GradientPainter extends CustomPainter {
class _GridPainter extends CustomPainter { const _GradientPainter();
final double spacing;
final Color color;
_GridPainter({required this.spacing, required this.color});
static const double maxSquare = 85;
static const double minSquare = 48; // 2x gap
@override @override
void paint(Canvas canvas, Size size) { void paint(Canvas canvas, Size size) {
final paint = Paint()..color = color; // 🎨 Main smooth background gradient
final rect = Offset.zero & size;
// ✅ outer padding included in layout math final backgroundGradient = const LinearGradient(
final innerWidth = size.width - spacing * 2; begin: Alignment.topLeft,
final innerHeight = size.height - spacing * 2; end: Alignment.bottomRight,
colors: [
Color(0xFF0F172A), // deep navy
Color(0xFF111827), // dark slate
],
);
int columns = 10; final paint = Paint()..shader = backgroundGradient.createShader(rect);
double calcSize(int cols) { canvas.drawRect(rect, paint);
return (innerWidth - (cols - 1) * spacing) / cols;
}
// choose columns safely // 🌈 soft glowing blobs (adds "cool gradient feel")
while (columns > 1 && calcSize(columns) < minSquare) { _drawGlow(
columns--; canvas,
} size,
offset: const Offset(0.2, 0.3),
radius: size.width * 0.8,
colors: [Colors.cyan.withOpacity(0.25), Colors.transparent],
);
double square = calcSize(columns); _drawGlow(
square = math.min(square, maxSquare); canvas,
size,
offset: const Offset(0.8, 0.6),
radius: size.width * 0.9,
colors: [Colors.purple.withOpacity(0.20), Colors.transparent],
);
final rows = (innerHeight / (square + spacing)).ceil(); _drawGlow(
canvas,
size,
offset: const Offset(0.5, 0.9),
radius: size.width * 0.7,
colors: [Colors.blue.withOpacity(0.20), Colors.transparent],
);
}
for (int row = 0; row < rows; row++) { void _drawGlow(
final y = spacing + row * (square + spacing); Canvas canvas,
Size size, {
required Offset offset,
required double radius,
required List<Color> colors,
}) {
final center = Offset(size.width * offset.dx, size.height * offset.dy);
for (int col = 0; col < columns; col++) { final gradient = RadialGradient(colors: colors, radius: 1.0);
final x = spacing + col * (square + spacing);
final rect = Rect.fromLTWH(x, y, square, square); final paint = Paint()
..shader = gradient.createShader(
Rect.fromCircle(center: center, radius: radius),
)
..maskFilter = const MaskFilter.blur(BlurStyle.normal, 60);
canvas.drawRRect( canvas.drawCircle(center, radius, paint);
RRect.fromRectAndRadius(rect, const Radius.circular(6)),
paint,
);
}
}
} }
@override @override
bool shouldRepaint(covariant _GridPainter oldDelegate) { bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
return oldDelegate.spacing != spacing || oldDelegate.color != color;
}
} }

View File

@@ -1,11 +1,15 @@
import 'dart:developer';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:softplayer_web/features/authorization/application/authorization_application.dart'; import 'package:softplayer_web/features/authorization/application/authorization_application.dart';
import 'package:softplayer_web/features/authorization/application/sign_in_data.dart'; import 'package:softplayer_web/features/authorization/application/sign_in_data.dart';
import 'package:toastification/toastification.dart';
class LoginForm extends ConsumerStatefulWidget { class LoginForm extends ConsumerStatefulWidget {
const LoginForm({super.key}); const LoginForm({super.key, required this.toggleAuth});
final VoidCallback toggleAuth;
@override @override
ConsumerState<LoginForm> createState() => _LoginForm(); ConsumerState<LoginForm> createState() => _LoginForm();
} }
@@ -16,21 +20,36 @@ class _LoginForm extends ConsumerState<LoginForm> {
final TextEditingController emailCtrl = TextEditingController(); final TextEditingController emailCtrl = TextEditingController();
final TextEditingController passwordCtrl = TextEditingController(); final TextEditingController passwordCtrl = TextEditingController();
void _submitForm() { Future<void> _submitForm() async {
if (_formKey.currentState!.validate()) { if (_formKey.currentState!.validate()) {
// If valid, you can use the values // If valid, you can use the values
final email = emailCtrl.text; final email = emailCtrl.text;
final password = passwordCtrl.text; final password = passwordCtrl.text;
final form = SignInData(email: email, password: password); final form = SignInData(email: email, password: password);
ref.read(authorizationControllerProvider.notifier).signin(form); try {
await ref.read(authorizationControllerProvider.notifier).signin(form);
} catch (e) {
if (!mounted) {
return;
}
log(e.toString());
toastification.show(
context: context,
type: ToastificationType.error,
style: ToastificationStyle.flatColored,
alignment: Alignment.topRight,
autoCloseDuration: const Duration(seconds: 4),
title: const Text('Authentication failed'),
description: Text(e.toString()),
showProgressBar: false,
);
}
} }
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final state = ref.watch(authorizationControllerProvider);
final controller = ref.read(authorizationControllerProvider.notifier); final controller = ref.read(authorizationControllerProvider.notifier);
final isLoading = state.isLoading;
return SizedBox( return SizedBox(
width: 400, width: 400,
child: Form( child: Form(
@@ -54,7 +73,7 @@ class _LoginForm extends ConsumerState<LoginForm> {
style: Theme.of(context).textTheme.bodyMedium, style: Theme.of(context).textTheme.bodyMedium,
), ),
TextButton( TextButton(
onPressed: controller.toggleAuthMode, onPressed: widget.toggleAuth,
style: TextButton.styleFrom( style: TextButton.styleFrom(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
minimumSize: Size(0, 0), minimumSize: Size(0, 0),
@@ -72,48 +91,26 @@ class _LoginForm extends ConsumerState<LoginForm> {
TextFormField( TextFormField(
onFieldSubmitted: (_) => _submitForm(), onFieldSubmitted: (_) => _submitForm(),
controller: emailCtrl, controller: emailCtrl,
decoration: InputDecoration(hintText: "Email address"),
validator: (value) { validator: (value) {
if (value == null || value.trim().isEmpty) { if (value == null || value.isEmpty) {
return 'Email is required'; return 'Email is required';
} }
final emailRegex = RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$');
if (!emailRegex.hasMatch(value.trim())) {
return 'Enter a valid email address';
}
return null; return null;
}, },
decoration: InputDecoration(hintText: "Email address"),
), ),
SizedBox(height: 16), SizedBox(height: 16),
TextFormField( TextFormField(
onFieldSubmitted: (_) => _submitForm(), onFieldSubmitted: (_) => _submitForm(),
controller: passwordCtrl, controller: passwordCtrl,
obscureText: true,
decoration: InputDecoration(hintText: "Password"),
validator: (value) { validator: (value) {
if (value == null || value.isEmpty) { if (value == null || value.isEmpty) {
return 'Password is required'; return 'Password is required';
} }
if (value.length < 12) {
return 'Password must be at least 12 characters long';
}
final hasNumber = RegExp(r'\d');
final hasSpecialChar = RegExp(
r'[!@#$%^&*(),.?":{}|<>_\-\\[\]\\/+=~`]',
);
if (!hasNumber.hasMatch(value)) {
return 'Password must contain at least one number';
}
if (!hasSpecialChar.hasMatch(value)) {
return 'Password must contain at least one special character';
}
return null; return null;
}, },
obscureText: true,
decoration: InputDecoration(hintText: "Password"),
), ),
SizedBox(height: 16), SizedBox(height: 16),
SizedBox( SizedBox(
@@ -121,13 +118,6 @@ class _LoginForm extends ConsumerState<LoginForm> {
child: Text("Forgot password?", textAlign: TextAlign.left), child: Text("Forgot password?", textAlign: TextAlign.left),
), ),
ElevatedButton(onPressed: _submitForm, child: const Text('Log in')), ElevatedButton(onPressed: _submitForm, child: const Text('Log in')),
if (isLoading)
Positioned.fill(
child: Container(
color: Colors.black.withValues(alpha: 0.2),
child: const Center(child: CircularProgressIndicator()),
),
),
], ],
), ),
), ),

View File

@@ -4,8 +4,9 @@ import 'package:softplayer_web/features/authorization/application/authorization_
import 'package:softplayer_web/features/authorization/application/sign_up_data.dart'; import 'package:softplayer_web/features/authorization/application/sign_up_data.dart';
class RegisterForm extends ConsumerStatefulWidget { class RegisterForm extends ConsumerStatefulWidget {
const RegisterForm({super.key}); const RegisterForm({super.key, required this.toggleAuth});
final VoidCallback toggleAuth;
@override @override
ConsumerState<RegisterForm> createState() => _RegisterForm(); ConsumerState<RegisterForm> createState() => _RegisterForm();
} }
@@ -61,7 +62,7 @@ class _RegisterForm extends ConsumerState<RegisterForm> {
style: Theme.of(context).textTheme.bodyMedium, style: Theme.of(context).textTheme.bodyMedium,
), ),
TextButton( TextButton(
onPressed: controller.toggleAuthMode, onPressed: widget.toggleAuth,
style: TextButton.styleFrom( style: TextButton.styleFrom(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
minimumSize: Size(0, 0), minimumSize: Size(0, 0),
@@ -80,18 +81,41 @@ class _RegisterForm extends ConsumerState<RegisterForm> {
controller: nameCtrl, controller: nameCtrl,
onFieldSubmitted: (_) => _submitForm(), onFieldSubmitted: (_) => _submitForm(),
decoration: InputDecoration(hintText: "Name"), decoration: InputDecoration(hintText: "Name"),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Password is required';
}
return null;
},
), ),
SizedBox(height: 16), SizedBox(height: 16),
TextFormField( TextFormField(
controller: surnameCtrl, controller: surnameCtrl,
onFieldSubmitted: (_) => _submitForm(), onFieldSubmitted: (_) => _submitForm(),
decoration: InputDecoration(hintText: "Surname"), decoration: InputDecoration(hintText: "Surname"),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Password is required';
}
return null;
},
), ),
SizedBox(height: 16), SizedBox(height: 16),
TextFormField( TextFormField(
controller: emailCtrl, controller: emailCtrl,
onFieldSubmitted: (_) => _submitForm(), onFieldSubmitted: (_) => _submitForm(),
decoration: InputDecoration(hintText: "Email address"), decoration: InputDecoration(hintText: "Email address"),
validator: (value) {
if (value == null || value.trim().isEmpty) {
return 'Email is required';
}
final emailRegex = RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$');
if (!emailRegex.hasMatch(value.trim())) {
return 'Enter a valid email address';
}
return null;
},
), ),
SizedBox(height: 16), SizedBox(height: 16),
TextFormField( TextFormField(
@@ -99,6 +123,30 @@ class _RegisterForm extends ConsumerState<RegisterForm> {
onFieldSubmitted: (_) => _submitForm(), onFieldSubmitted: (_) => _submitForm(),
obscureText: true, obscureText: true,
decoration: InputDecoration(hintText: "Password"), decoration: InputDecoration(hintText: "Password"),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Password is required';
}
if (value.length < 12) {
return 'Password must be at least 12 characters long';
}
final hasNumber = RegExp(r'\d');
final hasSpecialChar = RegExp(
r'[!@#$%^&*(),.?":{}|<>_\-\\[\]\\/+=~`]',
);
if (!hasNumber.hasMatch(value)) {
return 'Password must contain at least one number';
}
if (!hasSpecialChar.hasMatch(value)) {
return 'Password must contain at least one special character';
}
return null;
},
), ),
SizedBox(height: 16), SizedBox(height: 16),
TextFormField( TextFormField(
@@ -106,7 +154,19 @@ class _RegisterForm extends ConsumerState<RegisterForm> {
onFieldSubmitted: (_) => _submitForm(), onFieldSubmitted: (_) => _submitForm(),
obscureText: true, obscureText: true,
decoration: InputDecoration(hintText: "Repeat the password"), decoration: InputDecoration(hintText: "Repeat the password"),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Password is required';
}
if (value != passwordCtrl.text) {
return 'Passwords do not match';
}
return null;
},
), ),
SizedBox(height: 16),
ElevatedButton( ElevatedButton(
onPressed: _submitForm, onPressed: _submitForm,
child: const Text('Sign up'), child: const Text('Sign up'),

View File

@@ -11,6 +11,7 @@ class LightModeColors {
// Inputs // Inputs
static const inputBackground = Color(0xFFFFFFFF); static const inputBackground = Color(0xFFFFFFFF);
static const inputDefaultBorder = Color(0xFFD9D9D9); static const inputDefaultBorder = Color(0xFFD9D9D9);
static const inputHoverBorder = Color(0xFFC9CED6);
static const inputFocusedBorder = Color(0xFFEFFF1A); static const inputFocusedBorder = Color(0xFFEFFF1A);
// Text // Text

View File

@@ -72,10 +72,11 @@ class AppTheme {
width: 1.0, width: 1.0,
), ),
), ),
hoverColor: LightModeColors.inputBackground,
enabledBorder: OutlineInputBorder( enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(8.0)), borderRadius: BorderRadius.all(Radius.circular(8.0)),
borderSide: BorderSide( borderSide: BorderSide(
color: LightModeColors.inputDefaultBorder, color: LightModeColors.inputHoverBorder,
width: 1.0, width: 1.0,
), ),
), ),

View File

@@ -129,6 +129,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.1.2" version: "2.1.2"
equatable:
dependency: transitive
description:
name: equatable
sha256: "3e0141505477fd8ad55d6eb4e7776d3fe8430be8e497ccb1521370c3f21a3e2b"
url: "https://pub.dev"
source: hosted
version: "2.0.8"
fake_async: fake_async:
dependency: transitive dependency: transitive
description: description:
@@ -544,6 +552,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.3.0" version: "2.3.0"
pausable_timer:
dependency: transitive
description:
name: pausable_timer
sha256: "6ef1a95441ec3439de6fb63f39a011b67e693198e7dae14e20675c3c00e86074"
url: "https://pub.dev"
source: hosted
version: "3.1.0+3"
platform: platform:
dependency: transitive dependency: transitive
description: description:
@@ -734,6 +750,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.6.17" version: "0.6.17"
toastification:
dependency: "direct main"
description:
name: toastification
sha256: "66c96678e3dece8ba24de3ea31634bd65a80aaecb8105f9bafe946e5f0d7590a"
url: "https://pub.dev"
source: hosted
version: "3.2.0"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:
@@ -742,6 +766,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.4.0" version: "1.4.0"
uuid:
dependency: transitive
description:
name: uuid
sha256: "1fef9e8e11e2991bb773070d4656b7bd5d850967a2456cfc83cf47925ba79489"
url: "https://pub.dev"
source: hosted
version: "4.5.3"
vector_math: vector_math:
dependency: transitive dependency: transitive
description: description:

View File

@@ -23,6 +23,7 @@ dependencies:
go_router: ^17.2.3 go_router: ^17.2.3
flutter_secure_storage: ^10.2.0 flutter_secure_storage: ^10.2.0
jwt_decoder: ^2.0.1 jwt_decoder: ^2.0.1
toastification: ^3.2.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
sdk: flutter sdk: flutter