From 91c30e4bc0db9315e25a6a44b1f3e3e09fac4b68 Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Mon, 1 Apr 2024 08:50:44 +0200 Subject: [PATCH 01/43] chore: adapt the header appearance --- .../apps/admin_ui/lib/pages/login_page.dart | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/AdminUi/apps/admin_ui/lib/pages/login_page.dart b/AdminUi/apps/admin_ui/lib/pages/login_page.dart index 29fc7d23ab..7347101b87 100644 --- a/AdminUi/apps/admin_ui/lib/pages/login_page.dart +++ b/AdminUi/apps/admin_ui/lib/pages/login_page.dart @@ -36,7 +36,26 @@ class _LoginScreenState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: const Text('Enmeshed Admin UI - Login'), + title: Row( + mainAxisSize: MainAxisSize.min, + children: [ + SvgPicture.asset( + 'assets/logo.svg', + width: 30, + height: 30, + ), + const SizedBox(width: 10), + const Text( + 'enmeshed', + style: TextStyle(fontWeight: FontWeight.bold), + ), + const SizedBox(width: 10), + const Text('Admin UI'), + ], + ), + leading: const SizedBox( + width: 40, + ), ), body: Center( child: SizedBox( From 0c83a4981719b0e9d1fbbb5f59e012d37163e677 Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Mon, 1 Apr 2024 08:52:12 +0200 Subject: [PATCH 02/43] chore: add new design for login box --- .../apps/admin_ui/lib/pages/login_page.dart | 76 +++++++++++++------ 1 file changed, 54 insertions(+), 22 deletions(-) diff --git a/AdminUi/apps/admin_ui/lib/pages/login_page.dart b/AdminUi/apps/admin_ui/lib/pages/login_page.dart index 7347101b87..1d8b1f3c3f 100644 --- a/AdminUi/apps/admin_ui/lib/pages/login_page.dart +++ b/AdminUi/apps/admin_ui/lib/pages/login_page.dart @@ -57,33 +57,65 @@ class _LoginScreenState extends State { width: 40, ), ), - body: Center( - child: SizedBox( - width: 300, - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - SvgPicture.asset('assets/logo.svg', width: 200, height: 200), - const SizedBox(height: 40), - TextField( - controller: _apiKeyController, - focusNode: _apiKeyFocusNode, - decoration: const InputDecoration( - labelText: 'API Key', - border: OutlineInputBorder(), + body: SingleChildScrollView( + child: Padding( + padding: EdgeInsets.only(top: topPadding), + child: Align( + alignment: Alignment.topCenter, + child: SizedBox( + width: 500, + height: 250, + child: Card( + child: SizedBox( + width: 300, + child: Padding( + padding: const EdgeInsets.only(top: 20, left: 25, right: 25), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + TextField( + controller: _apiKeyController, + focusNode: _apiKeyFocusNode, + decoration: InputDecoration( + labelText: 'API Key', + border: const OutlineInputBorder(), + errorBorder: const OutlineInputBorder( + borderSide: BorderSide(color: Colors.red, width: 2), + ), + focusedErrorBorder: const OutlineInputBorder( + borderSide: BorderSide(color: Colors.red, width: 2), + ), + errorText: (_attemptedLogin && !apiKeyValid) ? 'Invalid API Key' : null, + ), + onSubmitted: (_) => _login(), + onChanged: (text) { + setState(() { + _isButtonEnabled = text.isNotEmpty; + _attemptedLogin = false; + apiKeyValid = false; + }); + }, + obscureText: true, + ), + const SizedBox(height: 20), + SizedBox( + width: double.infinity, + height: 40, + child: ElevatedButton( + onPressed: _isButtonEnabled ? _login : null, + child: const Text('Login'), + ), + ), + ], + ), + ), ), - onSubmitted: (_) => _login(), - obscureText: true, ), - const SizedBox(height: 20), - ElevatedButton( - onPressed: _login, - child: const Text('Login'), - ), - ], + ), ), ), ), + backgroundColor: const Color.fromARGB(255, 211, 228, 255), ); } From 067af12a9b0648e5921a0f6daa8aa885c7e57554 Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Mon, 1 Apr 2024 08:53:06 +0200 Subject: [PATCH 03/43] chore: adapt login position in padding widget via screen size --- AdminUi/apps/admin_ui/lib/pages/login_page.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AdminUi/apps/admin_ui/lib/pages/login_page.dart b/AdminUi/apps/admin_ui/lib/pages/login_page.dart index 1d8b1f3c3f..3092255f8c 100644 --- a/AdminUi/apps/admin_ui/lib/pages/login_page.dart +++ b/AdminUi/apps/admin_ui/lib/pages/login_page.dart @@ -34,6 +34,9 @@ class _LoginScreenState extends State { @override Widget build(BuildContext context) { + final screenSize = MediaQuery.of(context).size; + final topPadding = screenSize.height > 1080 ? screenSize.height * 0.2 : screenSize.height * 0.3; + return Scaffold( appBar: AppBar( title: Row( From 7f793987040812e0323fb7c550e255b615031b98 Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Mon, 1 Apr 2024 08:53:53 +0200 Subject: [PATCH 04/43] chore: logic for displaying the error message for attempted login --- AdminUi/apps/admin_ui/lib/pages/login_page.dart | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/AdminUi/apps/admin_ui/lib/pages/login_page.dart b/AdminUi/apps/admin_ui/lib/pages/login_page.dart index 3092255f8c..a22fecad14 100644 --- a/AdminUi/apps/admin_ui/lib/pages/login_page.dart +++ b/AdminUi/apps/admin_ui/lib/pages/login_page.dart @@ -17,6 +17,10 @@ class _LoginScreenState extends State { final _apiKeyController = TextEditingController(); final _apiKeyFocusNode = FocusNode(); + bool _isButtonEnabled = false; + bool apiKeyValid = false; + bool _attemptedLogin = false; + @override void initState() { super.initState(); @@ -123,21 +127,17 @@ class _LoginScreenState extends State { } Future _login() async { + _attemptedLogin = true; final apiKey = _apiKeyController.text.trim(); if (apiKey.isEmpty) return; const baseUrl = kIsWeb ? '' : String.fromEnvironment('base_url'); - final apiKeyValid = await AdminApiClient.validateApiKey(baseUrl: baseUrl, apiKey: apiKey); + apiKeyValid = await AdminApiClient.validateApiKey(baseUrl: baseUrl, apiKey: apiKey); if (!mounted) return; if (!apiKeyValid) { - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text('Invalid API Key'), - backgroundColor: Colors.red, - ), - ); + setState(() {}); return; } From 53277da37b42a63dc8d8dacff4d5173222913699 Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Mon, 1 Apr 2024 09:11:17 +0200 Subject: [PATCH 05/43] chore: remove error message --- AdminUi/apps/admin_ui/lib/pages/login_page.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AdminUi/apps/admin_ui/lib/pages/login_page.dart b/AdminUi/apps/admin_ui/lib/pages/login_page.dart index a22fecad14..adc54d612b 100644 --- a/AdminUi/apps/admin_ui/lib/pages/login_page.dart +++ b/AdminUi/apps/admin_ui/lib/pages/login_page.dart @@ -92,7 +92,7 @@ class _LoginScreenState extends State { focusedErrorBorder: const OutlineInputBorder( borderSide: BorderSide(color: Colors.red, width: 2), ), - errorText: (_attemptedLogin && !apiKeyValid) ? 'Invalid API Key' : null, + errorText: (_attemptedLogin && !apiKeyValid) ? '' : null, ), onSubmitted: (_) => _login(), onChanged: (text) { From a1f5bd95fb9e8377a19af827c5fa6fff8d14f9c1 Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Mon, 1 Apr 2024 09:13:51 +0200 Subject: [PATCH 06/43] chore: add error message --- AdminUi/apps/admin_ui/lib/pages/login_page.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AdminUi/apps/admin_ui/lib/pages/login_page.dart b/AdminUi/apps/admin_ui/lib/pages/login_page.dart index adc54d612b..a22fecad14 100644 --- a/AdminUi/apps/admin_ui/lib/pages/login_page.dart +++ b/AdminUi/apps/admin_ui/lib/pages/login_page.dart @@ -92,7 +92,7 @@ class _LoginScreenState extends State { focusedErrorBorder: const OutlineInputBorder( borderSide: BorderSide(color: Colors.red, width: 2), ), - errorText: (_attemptedLogin && !apiKeyValid) ? '' : null, + errorText: (_attemptedLogin && !apiKeyValid) ? 'Invalid API Key' : null, ), onSubmitted: (_) => _login(), onChanged: (text) { From 3aba8cd604ff7ac16778fd2e53d4aa19a7422e79 Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Mon, 1 Apr 2024 09:33:01 +0200 Subject: [PATCH 07/43] chore: change the button colors and add a text button --- .../apps/admin_ui/lib/pages/login_page.dart | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/AdminUi/apps/admin_ui/lib/pages/login_page.dart b/AdminUi/apps/admin_ui/lib/pages/login_page.dart index a22fecad14..fff58ca1cc 100644 --- a/AdminUi/apps/admin_ui/lib/pages/login_page.dart +++ b/AdminUi/apps/admin_ui/lib/pages/login_page.dart @@ -110,7 +110,27 @@ class _LoginScreenState extends State { height: 40, child: ElevatedButton( onPressed: _isButtonEnabled ? _login : null, - child: const Text('Login'), + style: _isButtonEnabled + ? const ButtonStyle( + backgroundColor: MaterialStatePropertyAll( + Color.fromARGB(255, 0, 47, 114), + ), + ) + : null, + child: Text( + 'Login', + style: TextStyle(color: _isButtonEnabled ? Colors.white : null), + ), + ), + ), + const SizedBox(height: 8), + Visibility( + visible: _attemptedLogin && !apiKeyValid, + child: TextButton( + onPressed: () { + // TODO: Implement what should happen when "Forgot API Key?" is pressed + }, + child: const Text('Forgot API Key?'), ), ), ], From 1aad577b5d39502c781cda637a9f014ea817abd9 Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Mon, 1 Apr 2024 09:33:42 +0200 Subject: [PATCH 08/43] chore: remove Visibility widget --- AdminUi/apps/admin_ui/lib/pages/login_page.dart | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/AdminUi/apps/admin_ui/lib/pages/login_page.dart b/AdminUi/apps/admin_ui/lib/pages/login_page.dart index fff58ca1cc..a6371a602e 100644 --- a/AdminUi/apps/admin_ui/lib/pages/login_page.dart +++ b/AdminUi/apps/admin_ui/lib/pages/login_page.dart @@ -124,14 +124,11 @@ class _LoginScreenState extends State { ), ), const SizedBox(height: 8), - Visibility( - visible: _attemptedLogin && !apiKeyValid, - child: TextButton( - onPressed: () { - // TODO: Implement what should happen when "Forgot API Key?" is pressed - }, - child: const Text('Forgot API Key?'), - ), + TextButton( + onPressed: () { + // TODO: Implement what should happen when "Forgot API Key?" is pressed + }, + child: const Text('Forgot API Key?'), ), ], ), From 9f34d13cd7dfb0fbc61123430cb0434a4be99857 Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Mon, 1 Apr 2024 09:37:36 +0200 Subject: [PATCH 09/43] chore: add text style for text button --- AdminUi/apps/admin_ui/lib/pages/login_page.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/AdminUi/apps/admin_ui/lib/pages/login_page.dart b/AdminUi/apps/admin_ui/lib/pages/login_page.dart index a6371a602e..dd8ffa4ec9 100644 --- a/AdminUi/apps/admin_ui/lib/pages/login_page.dart +++ b/AdminUi/apps/admin_ui/lib/pages/login_page.dart @@ -128,7 +128,12 @@ class _LoginScreenState extends State { onPressed: () { // TODO: Implement what should happen when "Forgot API Key?" is pressed }, - child: const Text('Forgot API Key?'), + child: const Text( + 'Forgot API Key?', + style: TextStyle( + color: Color.fromARGB(255, 0, 47, 114), + ), + ), ), ], ), From 8c909a0a8222e8c0b9e510ffe1f3af348367cbec Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Mon, 1 Apr 2024 09:40:23 +0200 Subject: [PATCH 10/43] chore: change todo comment according to the flutter style --- AdminUi/apps/admin_ui/lib/pages/login_page.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AdminUi/apps/admin_ui/lib/pages/login_page.dart b/AdminUi/apps/admin_ui/lib/pages/login_page.dart index dd8ffa4ec9..3eb766006e 100644 --- a/AdminUi/apps/admin_ui/lib/pages/login_page.dart +++ b/AdminUi/apps/admin_ui/lib/pages/login_page.dart @@ -126,7 +126,7 @@ class _LoginScreenState extends State { const SizedBox(height: 8), TextButton( onPressed: () { - // TODO: Implement what should happen when "Forgot API Key?" is pressed + // TODO(stamenione): Implement what should happen when "Forgot API Key?" is pressed }, child: const Text( 'Forgot API Key?', From b7275c058d2eee059951c4fac24aa9a0333b9cc9 Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Tue, 2 Apr 2024 11:32:23 +0200 Subject: [PATCH 11/43] refactor: extract the app title to be a separate widget --- .../lib/styles/widgets/app_title.dart | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 AdminUi/apps/admin_ui/lib/styles/widgets/app_title.dart diff --git a/AdminUi/apps/admin_ui/lib/styles/widgets/app_title.dart b/AdminUi/apps/admin_ui/lib/styles/widgets/app_title.dart new file mode 100644 index 0000000000..4b43a2d99b --- /dev/null +++ b/AdminUi/apps/admin_ui/lib/styles/widgets/app_title.dart @@ -0,0 +1,42 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_svg/flutter_svg.dart'; + +class AppTitle extends StatelessWidget { + const AppTitle({super.key}); + + @override + Widget build(BuildContext context) { + return Row( + mainAxisSize: MainAxisSize.min, + children: [ + SvgPicture.asset( + 'assets/logo.svg', + width: 30, + height: 30, + ), + const SizedBox(width: 10), + RichText( + text: TextSpan( + children: [ + TextSpan( + text: 'enmeshed', + style: TextStyle( + fontWeight: FontWeight.bold, + color: Theme.of(context).colorScheme.scrim, + fontSize: 25, + ), + ), + TextSpan( + text: ' Admin UI', + style: TextStyle( + color: Theme.of(context).colorScheme.scrim, + fontSize: 25, + ), + ), + ], + ), + ), + ], + ); + } +} From 36431b5bce0041f3e741f9da6b86052301abf94a Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Tue, 2 Apr 2024 12:35:25 +0200 Subject: [PATCH 12/43] refactor: extract text field to be reusable --- .../lib/styles/widgets/custom_text_field.dart | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 AdminUi/apps/admin_ui/lib/styles/widgets/custom_text_field.dart diff --git a/AdminUi/apps/admin_ui/lib/styles/widgets/custom_text_field.dart b/AdminUi/apps/admin_ui/lib/styles/widgets/custom_text_field.dart new file mode 100644 index 0000000000..30051088b2 --- /dev/null +++ b/AdminUi/apps/admin_ui/lib/styles/widgets/custom_text_field.dart @@ -0,0 +1,46 @@ +import 'package:admin_ui/theme/colors/custom_colors.dart'; +import 'package:flutter/material.dart'; + +class CustomTextField extends StatelessWidget { + final TextEditingController controller; + final FocusNode focusNode; + final String label; + final bool obscureText; + final String? errorText; + final void Function(String) onChanged; + final void Function(String) onSubmitted; + + const CustomTextField({ + required this.controller, + required this.focusNode, + required this.label, + required this.onChanged, + required this.onSubmitted, + this.obscureText = false, + this.errorText, + super.key, + }); + + @override + Widget build(BuildContext context) { + final customColors = Theme.of(context).extension(); + return TextField( + controller: controller, + focusNode: focusNode, + decoration: InputDecoration( + labelText: label, + border: const OutlineInputBorder(), + errorBorder: OutlineInputBorder( + borderSide: BorderSide(color: customColors?.error ?? Colors.red, width: 2), + ), + focusedErrorBorder: OutlineInputBorder( + borderSide: BorderSide(color: customColors?.error ?? Colors.red, width: 2), + ), + errorText: errorText, + ), + obscureText: obscureText, + onChanged: onChanged, + onSubmitted: onSubmitted, + ); + } +} From 5441fb7d3623363d0b8b1dc33a934d57cfeeb05a Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Tue, 2 Apr 2024 12:35:43 +0200 Subject: [PATCH 13/43] chore: use new app title widget --- AdminUi/apps/admin_ui/lib/pages/home_page.dart | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/AdminUi/apps/admin_ui/lib/pages/home_page.dart b/AdminUi/apps/admin_ui/lib/pages/home_page.dart index 94efa8693b..b980ee7c3b 100644 --- a/AdminUi/apps/admin_ui/lib/pages/home_page.dart +++ b/AdminUi/apps/admin_ui/lib/pages/home_page.dart @@ -1,5 +1,5 @@ +import 'package:admin_ui/styles/widgets/app_title.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_svg/flutter_svg.dart'; import 'package:get_it/get_it.dart'; import 'package:go_router/go_router.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -21,14 +21,7 @@ class _HomeScreenState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: Row( - mainAxisSize: MainAxisSize.min, - children: [ - SvgPicture.asset('assets/logo.svg', width: 30, height: 30), - const SizedBox(width: 10), - const Text('Enmeshed Admin UI'), - ], - ), + title: const AppTitle(), leading: IconButton( icon: const Icon(Icons.menu), onPressed: () { From d60fc2c0e40756599278bfaeaabd5d97f8f251f5 Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Tue, 2 Apr 2024 12:36:54 +0200 Subject: [PATCH 14/43] chore: use custom text field --- .../apps/admin_ui/lib/pages/login_page.dart | 94 +++---------------- 1 file changed, 14 insertions(+), 80 deletions(-) diff --git a/AdminUi/apps/admin_ui/lib/pages/login_page.dart b/AdminUi/apps/admin_ui/lib/pages/login_page.dart index 3eb766006e..b4f77239ee 100644 --- a/AdminUi/apps/admin_ui/lib/pages/login_page.dart +++ b/AdminUi/apps/admin_ui/lib/pages/login_page.dart @@ -64,87 +64,21 @@ class _LoginScreenState extends State { width: 40, ), ), - body: SingleChildScrollView( - child: Padding( - padding: EdgeInsets.only(top: topPadding), - child: Align( - alignment: Alignment.topCenter, - child: SizedBox( - width: 500, - height: 250, - child: Card( - child: SizedBox( - width: 300, - child: Padding( - padding: const EdgeInsets.only(top: 20, left: 25, right: 25), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - TextField( - controller: _apiKeyController, - focusNode: _apiKeyFocusNode, - decoration: InputDecoration( - labelText: 'API Key', - border: const OutlineInputBorder(), - errorBorder: const OutlineInputBorder( - borderSide: BorderSide(color: Colors.red, width: 2), - ), - focusedErrorBorder: const OutlineInputBorder( - borderSide: BorderSide(color: Colors.red, width: 2), - ), - errorText: (_attemptedLogin && !apiKeyValid) ? 'Invalid API Key' : null, - ), - onSubmitted: (_) => _login(), - onChanged: (text) { - setState(() { - _isButtonEnabled = text.isNotEmpty; - _attemptedLogin = false; - apiKeyValid = false; - }); - }, - obscureText: true, - ), - const SizedBox(height: 20), - SizedBox( - width: double.infinity, - height: 40, - child: ElevatedButton( - onPressed: _isButtonEnabled ? _login : null, - style: _isButtonEnabled - ? const ButtonStyle( - backgroundColor: MaterialStatePropertyAll( - Color.fromARGB(255, 0, 47, 114), - ), - ) - : null, - child: Text( - 'Login', - style: TextStyle(color: _isButtonEnabled ? Colors.white : null), - ), - ), - ), - const SizedBox(height: 8), - TextButton( - onPressed: () { - // TODO(stamenione): Implement what should happen when "Forgot API Key?" is pressed - }, - child: const Text( - 'Forgot API Key?', - style: TextStyle( - color: Color.fromARGB(255, 0, 47, 114), - ), - ), - ), - ], + child: CustomTextField( + controller: _apiKeyController, + focusNode: _apiKeyFocusNode, + label: 'API Key', + obscureText: true, + errorText: (_hasAttemptedLogin && !_isApiKeyValid) ? 'Invalid API Key' : null, + onChanged: (text) { + setState(() { + _isButtonEnabled = text.isNotEmpty; + _hasAttemptedLogin = false; + _isApiKeyValid = false; + }); + }, + onSubmitted: (_) => _login(), ), - ), - ), - ), - ), - ), - ), - ), - backgroundColor: const Color.fromARGB(255, 211, 228, 255), ); } From b04098dccdfac0a0028019569fa6a778cfde818d Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Tue, 2 Apr 2024 12:37:30 +0200 Subject: [PATCH 15/43] chore: make the text field fixed height --- AdminUi/apps/admin_ui/lib/pages/login_page.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AdminUi/apps/admin_ui/lib/pages/login_page.dart b/AdminUi/apps/admin_ui/lib/pages/login_page.dart index b4f77239ee..dc773c5c14 100644 --- a/AdminUi/apps/admin_ui/lib/pages/login_page.dart +++ b/AdminUi/apps/admin_ui/lib/pages/login_page.dart @@ -64,6 +64,8 @@ class _LoginScreenState extends State { width: 40, ), ), + SizedBox( + height: 100, child: CustomTextField( controller: _apiKeyController, focusNode: _apiKeyFocusNode, @@ -79,6 +81,7 @@ class _LoginScreenState extends State { }, onSubmitted: (_) => _login(), ), + ), ); } From 0ff34d72f1e4a26f611ac338a16c76f7b26256b8 Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Tue, 2 Apr 2024 12:38:40 +0200 Subject: [PATCH 16/43] chore: rename variables and make them private --- AdminUi/apps/admin_ui/lib/pages/login_page.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/AdminUi/apps/admin_ui/lib/pages/login_page.dart b/AdminUi/apps/admin_ui/lib/pages/login_page.dart index dc773c5c14..6195ac1e92 100644 --- a/AdminUi/apps/admin_ui/lib/pages/login_page.dart +++ b/AdminUi/apps/admin_ui/lib/pages/login_page.dart @@ -18,8 +18,8 @@ class _LoginScreenState extends State { final _apiKeyFocusNode = FocusNode(); bool _isButtonEnabled = false; - bool apiKeyValid = false; - bool _attemptedLogin = false; + bool _isApiKeyValid = false; + bool _hasAttemptedLogin = false; @override void initState() { @@ -86,16 +86,16 @@ class _LoginScreenState extends State { } Future _login() async { - _attemptedLogin = true; + _hasAttemptedLogin = true; final apiKey = _apiKeyController.text.trim(); if (apiKey.isEmpty) return; const baseUrl = kIsWeb ? '' : String.fromEnvironment('base_url'); - apiKeyValid = await AdminApiClient.validateApiKey(baseUrl: baseUrl, apiKey: apiKey); + _isApiKeyValid = await AdminApiClient.validateApiKey(baseUrl: baseUrl, apiKey: apiKey); if (!mounted) return; - if (!apiKeyValid) { + if (!_isApiKeyValid) { setState(() {}); return; } From 702d11d8ed7f8d658b4c7a69a5aaa55f81773629 Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Tue, 2 Apr 2024 12:38:58 +0200 Subject: [PATCH 17/43] chore: update imports --- AdminUi/apps/admin_ui/lib/pages/login_page.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AdminUi/apps/admin_ui/lib/pages/login_page.dart b/AdminUi/apps/admin_ui/lib/pages/login_page.dart index 6195ac1e92..2e6a1355b3 100644 --- a/AdminUi/apps/admin_ui/lib/pages/login_page.dart +++ b/AdminUi/apps/admin_ui/lib/pages/login_page.dart @@ -1,4 +1,7 @@ import 'package:admin_api_sdk/admin_api_sdk.dart'; +import 'package:admin_ui/styles/widgets/app_title.dart'; +import 'package:admin_ui/styles/widgets/custom_text_field.dart'; +import 'package:admin_ui/theme/colors/custom_colors.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; From 63fc066d636e585a58e3e662fca9166a61a15cc6 Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Tue, 2 Apr 2024 12:39:28 +0200 Subject: [PATCH 18/43] chore: use extracted app title widget --- .../apps/admin_ui/lib/pages/login_page.dart | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/AdminUi/apps/admin_ui/lib/pages/login_page.dart b/AdminUi/apps/admin_ui/lib/pages/login_page.dart index 2e6a1355b3..6c225e15fa 100644 --- a/AdminUi/apps/admin_ui/lib/pages/login_page.dart +++ b/AdminUi/apps/admin_ui/lib/pages/login_page.dart @@ -46,23 +46,7 @@ class _LoginScreenState extends State { return Scaffold( appBar: AppBar( - title: Row( - mainAxisSize: MainAxisSize.min, - children: [ - SvgPicture.asset( - 'assets/logo.svg', - width: 30, - height: 30, - ), - const SizedBox(width: 10), - const Text( - 'enmeshed', - style: TextStyle(fontWeight: FontWeight.bold), - ), - const SizedBox(width: 10), - const Text('Admin UI'), - ], - ), + title: const AppTitle(), leading: const SizedBox( width: 40, ), From 0fffd62026f04db70520f43510ed8f5b3eb0dc5e Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Tue, 2 Apr 2024 12:40:38 +0200 Subject: [PATCH 19/43] chore: remove unnecessary widgets and center the card --- AdminUi/apps/admin_ui/lib/pages/login_page.dart | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/AdminUi/apps/admin_ui/lib/pages/login_page.dart b/AdminUi/apps/admin_ui/lib/pages/login_page.dart index 6c225e15fa..a19aa6ae4d 100644 --- a/AdminUi/apps/admin_ui/lib/pages/login_page.dart +++ b/AdminUi/apps/admin_ui/lib/pages/login_page.dart @@ -51,6 +51,15 @@ class _LoginScreenState extends State { width: 40, ), ), + body: Center( + child: Card( + child: SizedBox( + width: 400, + child: Padding( + padding: const EdgeInsets.all(25), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ SizedBox( height: 100, child: CustomTextField( @@ -69,6 +78,12 @@ class _LoginScreenState extends State { onSubmitted: (_) => _login(), ), ), + ], + ), + ), + ), + ), + ), ); } From 0cafd434043ae9d258912582cfad0e1684cb84bb Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Tue, 2 Apr 2024 12:41:41 +0200 Subject: [PATCH 20/43] chore: add custom colors and move login button to the bottom --- .../apps/admin_ui/lib/pages/login_page.dart | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/AdminUi/apps/admin_ui/lib/pages/login_page.dart b/AdminUi/apps/admin_ui/lib/pages/login_page.dart index a19aa6ae4d..e39838f09b 100644 --- a/AdminUi/apps/admin_ui/lib/pages/login_page.dart +++ b/AdminUi/apps/admin_ui/lib/pages/login_page.dart @@ -41,8 +41,7 @@ class _LoginScreenState extends State { @override Widget build(BuildContext context) { - final screenSize = MediaQuery.of(context).size; - final topPadding = screenSize.height > 1080 ? screenSize.height * 0.2 : screenSize.height * 0.3; + final customColors = Theme.of(context).extension(); return Scaffold( appBar: AppBar( @@ -78,12 +77,32 @@ class _LoginScreenState extends State { onSubmitted: (_) => _login(), ), ), + const SizedBox(height: 20), + SizedBox( + width: double.infinity, + height: 40, + child: ElevatedButton( + onPressed: _isButtonEnabled ? _login : null, + style: _isButtonEnabled + ? ButtonStyle( + backgroundColor: MaterialStatePropertyAll( + Theme.of(context).colorScheme.primary, + ), + ) + : null, + child: Text( + 'Login', + style: TextStyle(color: _isButtonEnabled ? customColors?.onNeutralvariant : null), + ), + ), + ), ], ), ), ), ), ), + backgroundColor: Theme.of(context).colorScheme.inversePrimary, ); } From 979defbecb38daa1f7bb082cbf26c0d8b7b5b5a1 Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Tue, 2 Apr 2024 12:42:00 +0200 Subject: [PATCH 21/43] chore: remove unused import --- AdminUi/apps/admin_ui/lib/pages/login_page.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/AdminUi/apps/admin_ui/lib/pages/login_page.dart b/AdminUi/apps/admin_ui/lib/pages/login_page.dart index e39838f09b..a7e5a1cf7b 100644 --- a/AdminUi/apps/admin_ui/lib/pages/login_page.dart +++ b/AdminUi/apps/admin_ui/lib/pages/login_page.dart @@ -4,7 +4,6 @@ import 'package:admin_ui/styles/widgets/custom_text_field.dart'; import 'package:admin_ui/theme/colors/custom_colors.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_svg/flutter_svg.dart'; import 'package:get_it/get_it.dart'; import 'package:go_router/go_router.dart'; import 'package:shared_preferences/shared_preferences.dart'; From 61d3eac790c2204d07dc069a0a0e9b475629d132 Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Tue, 2 Apr 2024 12:45:16 +0200 Subject: [PATCH 22/43] refactor: rename folder and files appropriately --- AdminUi/apps/admin_ui/lib/main.dart | 2 +- AdminUi/apps/admin_ui/lib/pages/pages.dart | 3 --- .../lib/{pages/home_page.dart => screens/home_screen.dart} | 0 .../lib/{pages/login_page.dart => screens/login_screen.dart} | 0 AdminUi/apps/admin_ui/lib/screens/screens.dart | 3 +++ .../{pages/splash_page.dart => screens/splash_screens.dart} | 0 6 files changed, 4 insertions(+), 4 deletions(-) delete mode 100644 AdminUi/apps/admin_ui/lib/pages/pages.dart rename AdminUi/apps/admin_ui/lib/{pages/home_page.dart => screens/home_screen.dart} (100%) rename AdminUi/apps/admin_ui/lib/{pages/login_page.dart => screens/login_screen.dart} (100%) create mode 100644 AdminUi/apps/admin_ui/lib/screens/screens.dart rename AdminUi/apps/admin_ui/lib/{pages/splash_page.dart => screens/splash_screens.dart} (100%) diff --git a/AdminUi/apps/admin_ui/lib/main.dart b/AdminUi/apps/admin_ui/lib/main.dart index 403185b732..7456e6c65d 100644 --- a/AdminUi/apps/admin_ui/lib/main.dart +++ b/AdminUi/apps/admin_ui/lib/main.dart @@ -4,7 +4,7 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'home/home.dart'; -import 'pages/pages.dart'; +import 'screens/screens.dart'; import 'setup/setup_desktop.dart' if (dart.library.html) 'setup/setup_web.dart'; void main() async { diff --git a/AdminUi/apps/admin_ui/lib/pages/pages.dart b/AdminUi/apps/admin_ui/lib/pages/pages.dart deleted file mode 100644 index bac7e17980..0000000000 --- a/AdminUi/apps/admin_ui/lib/pages/pages.dart +++ /dev/null @@ -1,3 +0,0 @@ -export 'home_page.dart'; -export 'login_page.dart'; -export 'splash_page.dart'; diff --git a/AdminUi/apps/admin_ui/lib/pages/home_page.dart b/AdminUi/apps/admin_ui/lib/screens/home_screen.dart similarity index 100% rename from AdminUi/apps/admin_ui/lib/pages/home_page.dart rename to AdminUi/apps/admin_ui/lib/screens/home_screen.dart diff --git a/AdminUi/apps/admin_ui/lib/pages/login_page.dart b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart similarity index 100% rename from AdminUi/apps/admin_ui/lib/pages/login_page.dart rename to AdminUi/apps/admin_ui/lib/screens/login_screen.dart diff --git a/AdminUi/apps/admin_ui/lib/screens/screens.dart b/AdminUi/apps/admin_ui/lib/screens/screens.dart new file mode 100644 index 0000000000..649399d610 --- /dev/null +++ b/AdminUi/apps/admin_ui/lib/screens/screens.dart @@ -0,0 +1,3 @@ +export 'home_screen.dart'; +export 'login_screen.dart'; +export 'splash_screens.dart'; diff --git a/AdminUi/apps/admin_ui/lib/pages/splash_page.dart b/AdminUi/apps/admin_ui/lib/screens/splash_screens.dart similarity index 100% rename from AdminUi/apps/admin_ui/lib/pages/splash_page.dart rename to AdminUi/apps/admin_ui/lib/screens/splash_screens.dart From 72c4cdecb17d18c71b8dad396025052b42b7c111 Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Tue, 2 Apr 2024 12:54:57 +0200 Subject: [PATCH 23/43] refactor: extract sized box into a separate custom widget --- .../admin_ui/lib/screens/login_screen.dart | 68 +++++++------------ .../widgets/custom_styled_container.dart | 25 +++++++ 2 files changed, 48 insertions(+), 45 deletions(-) create mode 100644 AdminUi/apps/admin_ui/lib/styles/widgets/custom_styled_container.dart diff --git a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart index a7e5a1cf7b..f13dfe0ace 100644 --- a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart +++ b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart @@ -1,5 +1,6 @@ import 'package:admin_api_sdk/admin_api_sdk.dart'; import 'package:admin_ui/styles/widgets/app_title.dart'; +import 'package:admin_ui/styles/widgets/custom_styled_container.dart'; import 'package:admin_ui/styles/widgets/custom_text_field.dart'; import 'package:admin_ui/theme/colors/custom_colors.dart'; import 'package:flutter/foundation.dart'; @@ -51,52 +52,29 @@ class _LoginScreenState extends State { ), body: Center( child: Card( - child: SizedBox( - width: 400, - child: Padding( - padding: const EdgeInsets.all(25), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - SizedBox( - height: 100, - child: CustomTextField( - controller: _apiKeyController, - focusNode: _apiKeyFocusNode, - label: 'API Key', - obscureText: true, - errorText: (_hasAttemptedLogin && !_isApiKeyValid) ? 'Invalid API Key' : null, - onChanged: (text) { - setState(() { - _isButtonEnabled = text.isNotEmpty; - _hasAttemptedLogin = false; - _isApiKeyValid = false; - }); - }, - onSubmitted: (_) => _login(), - ), + child: CustomStyledContainer( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + SizedBox( + height: 100, + child: CustomTextField( + controller: _apiKeyController, + focusNode: _apiKeyFocusNode, + label: 'API Key', + obscureText: true, + errorText: (_hasAttemptedLogin && !_isApiKeyValid) ? 'Invalid API Key' : null, + onChanged: (text) { + setState(() { + _isButtonEnabled = text.isNotEmpty; + _hasAttemptedLogin = false; + _isApiKeyValid = false; + }); + }, + onSubmitted: (_) => _login(), ), - const SizedBox(height: 20), - SizedBox( - width: double.infinity, - height: 40, - child: ElevatedButton( - onPressed: _isButtonEnabled ? _login : null, - style: _isButtonEnabled - ? ButtonStyle( - backgroundColor: MaterialStatePropertyAll( - Theme.of(context).colorScheme.primary, - ), - ) - : null, - child: Text( - 'Login', - style: TextStyle(color: _isButtonEnabled ? customColors?.onNeutralvariant : null), - ), - ), - ), - ], - ), + ), + ], ), ), ), diff --git a/AdminUi/apps/admin_ui/lib/styles/widgets/custom_styled_container.dart b/AdminUi/apps/admin_ui/lib/styles/widgets/custom_styled_container.dart new file mode 100644 index 0000000000..3e2f33f3d9 --- /dev/null +++ b/AdminUi/apps/admin_ui/lib/styles/widgets/custom_styled_container.dart @@ -0,0 +1,25 @@ +import 'package:flutter/material.dart'; + +class CustomStyledContainer extends StatelessWidget { + final Widget child; + final double width; + final EdgeInsetsGeometry padding; + + const CustomStyledContainer({ + required this.child, + this.width = 400.0, + this.padding = const EdgeInsets.all(25), + super.key, + }); + + @override + Widget build(BuildContext context) { + return SizedBox( + width: width, + child: Padding( + padding: padding, + child: child, + ), + ); + } +} From befe45535ec7d0cca203d4b77df56353b10dcaca Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Tue, 2 Apr 2024 12:55:26 +0200 Subject: [PATCH 24/43] refactor: extract elevated button into a separate custom widget --- .../admin_ui/lib/screens/login_screen.dart | 9 +++++ .../widgets/custom_elevated_button.dart | 38 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 AdminUi/apps/admin_ui/lib/styles/widgets/custom_elevated_button.dart diff --git a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart index f13dfe0ace..b8d1d3b319 100644 --- a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart +++ b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart @@ -1,5 +1,6 @@ import 'package:admin_api_sdk/admin_api_sdk.dart'; import 'package:admin_ui/styles/widgets/app_title.dart'; +import 'package:admin_ui/styles/widgets/custom_elevated_button.dart'; import 'package:admin_ui/styles/widgets/custom_styled_container.dart'; import 'package:admin_ui/styles/widgets/custom_text_field.dart'; import 'package:admin_ui/theme/colors/custom_colors.dart'; @@ -74,6 +75,14 @@ class _LoginScreenState extends State { onSubmitted: (_) => _login(), ), ), + const SizedBox(height: 20), + CustomElevatedButton( + text: 'Login', + isEnabled: _isButtonEnabled, + onPressed: _login, + backgroundColor: Theme.of(context).colorScheme.primary, + textColor: customColors?.onNeutralvariant, + ), ], ), ), diff --git a/AdminUi/apps/admin_ui/lib/styles/widgets/custom_elevated_button.dart b/AdminUi/apps/admin_ui/lib/styles/widgets/custom_elevated_button.dart new file mode 100644 index 0000000000..d96c82ad06 --- /dev/null +++ b/AdminUi/apps/admin_ui/lib/styles/widgets/custom_elevated_button.dart @@ -0,0 +1,38 @@ +import 'package:flutter/material.dart'; + +class CustomElevatedButton extends StatelessWidget { + final String text; + final bool isEnabled; + final VoidCallback? onPressed; + final Color? backgroundColor; + final Color? textColor; + + const CustomElevatedButton({ + required this.text, + required this.isEnabled, + this.onPressed, + this.backgroundColor, + this.textColor, + super.key, + }); + + @override + Widget build(BuildContext context) { + return SizedBox( + width: double.infinity, + height: 40, + child: ElevatedButton( + onPressed: isEnabled ? onPressed : null, + style: ButtonStyle( + backgroundColor: MaterialStatePropertyAll( + isEnabled ? backgroundColor ?? Theme.of(context).colorScheme.primary : null, + ), + ), + child: Text( + text, + style: TextStyle(color: isEnabled ? textColor ?? Colors.white : null), + ), + ), + ); + } +} From 27a6132bcd127e0c5e1c74e7db32c049aaf123e9 Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Tue, 2 Apr 2024 13:05:27 +0200 Subject: [PATCH 25/43] chore: make the variable private --- AdminUi/apps/admin_ui/lib/screens/login_screen.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart index b8d1d3b319..026aab4d81 100644 --- a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart +++ b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart @@ -42,7 +42,7 @@ class _LoginScreenState extends State { @override Widget build(BuildContext context) { - final customColors = Theme.of(context).extension(); + final _customColors = Theme.of(context).extension(); return Scaffold( appBar: AppBar( @@ -81,7 +81,7 @@ class _LoginScreenState extends State { isEnabled: _isButtonEnabled, onPressed: _login, backgroundColor: Theme.of(context).colorScheme.primary, - textColor: customColors?.onNeutralvariant, + textColor: _customColors?.onNeutralvariant, ), ], ), From 0fb491d500b5ae61230de6c89697ae9542e0dc60 Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Tue, 2 Apr 2024 13:07:02 +0200 Subject: [PATCH 26/43] chore: local variable should not start with underscore --- AdminUi/apps/admin_ui/lib/screens/login_screen.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart index 026aab4d81..b8d1d3b319 100644 --- a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart +++ b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart @@ -42,7 +42,7 @@ class _LoginScreenState extends State { @override Widget build(BuildContext context) { - final _customColors = Theme.of(context).extension(); + final customColors = Theme.of(context).extension(); return Scaffold( appBar: AppBar( @@ -81,7 +81,7 @@ class _LoginScreenState extends State { isEnabled: _isButtonEnabled, onPressed: _login, backgroundColor: Theme.of(context).colorScheme.primary, - textColor: _customColors?.onNeutralvariant, + textColor: customColors?.onNeutralvariant, ), ], ), From a7d67c98915c5938b29ea592443993cace7b11eb Mon Sep 17 00:00:00 2001 From: Vladimir Vuckovic Date: Tue, 2 Apr 2024 15:12:54 +0200 Subject: [PATCH 27/43] chore: add DI for baseUrl --- AdminUi/apps/admin_ui/lib/main.dart | 21 ++++++++++++++++--- .../admin_ui/lib/screens/home_screen.dart | 2 ++ .../admin_ui/lib/screens/login_screen.dart | 7 ++++--- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/AdminUi/apps/admin_ui/lib/main.dart b/AdminUi/apps/admin_ui/lib/main.dart index 7456e6c65d..7a56d7ac8e 100644 --- a/AdminUi/apps/admin_ui/lib/main.dart +++ b/AdminUi/apps/admin_ui/lib/main.dart @@ -1,20 +1,35 @@ import 'package:admin_ui/theme/colors/color_schemes.dart'; import 'package:admin_ui/theme/colors/custom_colors.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:get_it/get_it.dart'; import 'package:go_router/go_router.dart'; import 'home/home.dart'; import 'screens/screens.dart'; import 'setup/setup_desktop.dart' if (dart.library.html) 'setup/setup_web.dart'; +class AppConfig { + final String baseUrl; + AppConfig({required this.baseUrl}); +} + +void setupLocator() { + if (!GetIt.I.isRegistered()) { + GetIt.I.registerSingleton( + AppConfig(baseUrl: kIsWeb ? '' : const String.fromEnvironment('base_url')), + ); + } +} + void main() async { WidgetsFlutterBinding.ensureInitialized(); + setupLocator(); + await setup(); - runApp( - const AdminUiApp(), - ); + runApp(const AdminUiApp()); } final _rootNavigatorKey = GlobalKey(); diff --git a/AdminUi/apps/admin_ui/lib/screens/home_screen.dart b/AdminUi/apps/admin_ui/lib/screens/home_screen.dart index b980ee7c3b..b9a35ae263 100644 --- a/AdminUi/apps/admin_ui/lib/screens/home_screen.dart +++ b/AdminUi/apps/admin_ui/lib/screens/home_screen.dart @@ -1,3 +1,4 @@ +import 'package:admin_ui/main.dart'; import 'package:admin_ui/styles/widgets/app_title.dart'; import 'package:flutter/material.dart'; import 'package:get_it/get_it.dart'; @@ -79,6 +80,7 @@ class _HomeScreenState extends State { final sp = await SharedPreferences.getInstance(); await sp.remove('api_key'); await GetIt.I.reset(); + setupLocator(); if (mounted) context.go('/login'); } } diff --git a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart index b8d1d3b319..4b1f4b72d3 100644 --- a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart +++ b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart @@ -1,10 +1,10 @@ import 'package:admin_api_sdk/admin_api_sdk.dart'; +import 'package:admin_ui/main.dart'; import 'package:admin_ui/styles/widgets/app_title.dart'; import 'package:admin_ui/styles/widgets/custom_elevated_button.dart'; import 'package:admin_ui/styles/widgets/custom_styled_container.dart'; import 'package:admin_ui/styles/widgets/custom_text_field.dart'; import 'package:admin_ui/theme/colors/custom_colors.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:get_it/get_it.dart'; import 'package:go_router/go_router.dart'; @@ -28,7 +28,6 @@ class _LoginScreenState extends State { @override void initState() { super.initState(); - _apiKeyFocusNode.requestFocus(); } @@ -97,7 +96,7 @@ class _LoginScreenState extends State { final apiKey = _apiKeyController.text.trim(); if (apiKey.isEmpty) return; - const baseUrl = kIsWeb ? '' : String.fromEnvironment('base_url'); + final baseUrl = GetIt.I().baseUrl; _isApiKeyValid = await AdminApiClient.validateApiKey(baseUrl: baseUrl, apiKey: apiKey); if (!mounted) return; @@ -111,6 +110,8 @@ class _LoginScreenState extends State { await sp.setString('api_key', apiKey); await GetIt.I.reset(); + setupLocator(); + GetIt.I.registerSingleton(await AdminApiClient.create(baseUrl: baseUrl, apiKey: apiKey)); if (mounted) context.go('/dashboard'); } From 48afead8e5070eeb18274dcb53f46e4bcf5847a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Tue, 2 Apr 2024 16:56:03 +0200 Subject: [PATCH 28/43] fix: untangle coding --- AdminUi/apps/admin_ui/lib/main.dart | 17 ----------------- .../apps/admin_ui/lib/screens/home_screen.dart | 8 +++++--- .../apps/admin_ui/lib/screens/login_screen.dart | 7 +++---- .../apps/admin_ui/lib/setup/setup_desktop.dart | 7 +++++++ AdminUi/apps/admin_ui/lib/setup/setup_web.dart | 6 +++++- AdminUi/apps/admin_ui/lib/utils/app_config.dart | 5 +++++ AdminUi/apps/admin_ui/lib/utils/extensions.dart | 9 +++++++++ AdminUi/apps/admin_ui/lib/utils/utils.dart | 2 ++ 8 files changed, 36 insertions(+), 25 deletions(-) create mode 100644 AdminUi/apps/admin_ui/lib/utils/app_config.dart create mode 100644 AdminUi/apps/admin_ui/lib/utils/extensions.dart create mode 100644 AdminUi/apps/admin_ui/lib/utils/utils.dart diff --git a/AdminUi/apps/admin_ui/lib/main.dart b/AdminUi/apps/admin_ui/lib/main.dart index 7a56d7ac8e..aa70d89ca2 100644 --- a/AdminUi/apps/admin_ui/lib/main.dart +++ b/AdminUi/apps/admin_ui/lib/main.dart @@ -1,32 +1,15 @@ import 'package:admin_ui/theme/colors/color_schemes.dart'; import 'package:admin_ui/theme/colors/custom_colors.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:get_it/get_it.dart'; import 'package:go_router/go_router.dart'; import 'home/home.dart'; import 'screens/screens.dart'; import 'setup/setup_desktop.dart' if (dart.library.html) 'setup/setup_web.dart'; -class AppConfig { - final String baseUrl; - AppConfig({required this.baseUrl}); -} - -void setupLocator() { - if (!GetIt.I.isRegistered()) { - GetIt.I.registerSingleton( - AppConfig(baseUrl: kIsWeb ? '' : const String.fromEnvironment('base_url')), - ); - } -} - void main() async { WidgetsFlutterBinding.ensureInitialized(); - setupLocator(); - await setup(); runApp(const AdminUiApp()); diff --git a/AdminUi/apps/admin_ui/lib/screens/home_screen.dart b/AdminUi/apps/admin_ui/lib/screens/home_screen.dart index b9a35ae263..74fb299bf9 100644 --- a/AdminUi/apps/admin_ui/lib/screens/home_screen.dart +++ b/AdminUi/apps/admin_ui/lib/screens/home_screen.dart @@ -1,10 +1,12 @@ -import 'package:admin_ui/main.dart'; +import 'package:admin_api_sdk/admin_api_sdk.dart'; import 'package:admin_ui/styles/widgets/app_title.dart'; import 'package:flutter/material.dart'; import 'package:get_it/get_it.dart'; import 'package:go_router/go_router.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import '/utils/utils.dart'; + class HomeScreen extends StatefulWidget { final Widget child; final String location; @@ -79,8 +81,8 @@ class _HomeScreenState extends State { Future _logout() async { final sp = await SharedPreferences.getInstance(); await sp.remove('api_key'); - await GetIt.I.reset(); - setupLocator(); + await GetIt.I.unregisterIfRegistered(); + if (mounted) context.go('/login'); } } diff --git a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart index 4b1f4b72d3..f39c505918 100644 --- a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart +++ b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart @@ -1,5 +1,4 @@ import 'package:admin_api_sdk/admin_api_sdk.dart'; -import 'package:admin_ui/main.dart'; import 'package:admin_ui/styles/widgets/app_title.dart'; import 'package:admin_ui/styles/widgets/custom_elevated_button.dart'; import 'package:admin_ui/styles/widgets/custom_styled_container.dart'; @@ -10,6 +9,8 @@ import 'package:get_it/get_it.dart'; import 'package:go_router/go_router.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import '/utils/utils.dart'; + class LoginScreen extends StatefulWidget { const LoginScreen({super.key}); @@ -108,10 +109,8 @@ class _LoginScreenState extends State { final sp = await SharedPreferences.getInstance(); await sp.setString('api_key', apiKey); - await GetIt.I.reset(); - - setupLocator(); + await GetIt.I.unregisterIfRegistered(); GetIt.I.registerSingleton(await AdminApiClient.create(baseUrl: baseUrl, apiKey: apiKey)); if (mounted) context.go('/dashboard'); } diff --git a/AdminUi/apps/admin_ui/lib/setup/setup_desktop.dart b/AdminUi/apps/admin_ui/lib/setup/setup_desktop.dart index 728426f881..754f64f620 100644 --- a/AdminUi/apps/admin_ui/lib/setup/setup_desktop.dart +++ b/AdminUi/apps/admin_ui/lib/setup/setup_desktop.dart @@ -1,10 +1,17 @@ import 'dart:io'; import 'dart:ui'; +import 'package:get_it/get_it.dart'; import 'package:window_size/window_size.dart'; +import '/utils/utils.dart'; + Future setup() async { if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) { setWindowMinSize(const Size(1200, 800)); } + + GetIt.I.registerSingleton( + AppConfig(baseUrl: const String.fromEnvironment('base_url')), + ); } diff --git a/AdminUi/apps/admin_ui/lib/setup/setup_web.dart b/AdminUi/apps/admin_ui/lib/setup/setup_web.dart index a8c68561e1..1766df17bf 100644 --- a/AdminUi/apps/admin_ui/lib/setup/setup_web.dart +++ b/AdminUi/apps/admin_ui/lib/setup/setup_web.dart @@ -1,3 +1,7 @@ +import 'package:get_it/get_it.dart'; + +import '/utils/app_config.dart'; + Future setup() async { - // No setup required for web + GetIt.I.registerSingleton(AppConfig(baseUrl: '')); } diff --git a/AdminUi/apps/admin_ui/lib/utils/app_config.dart b/AdminUi/apps/admin_ui/lib/utils/app_config.dart new file mode 100644 index 0000000000..022c9bca6b --- /dev/null +++ b/AdminUi/apps/admin_ui/lib/utils/app_config.dart @@ -0,0 +1,5 @@ +class AppConfig { + final String baseUrl; + + AppConfig({required this.baseUrl}); +} diff --git a/AdminUi/apps/admin_ui/lib/utils/extensions.dart b/AdminUi/apps/admin_ui/lib/utils/extensions.dart new file mode 100644 index 0000000000..aef82fefaf --- /dev/null +++ b/AdminUi/apps/admin_ui/lib/utils/extensions.dart @@ -0,0 +1,9 @@ +import 'package:get_it/get_it.dart'; + +extension UnregisterIfRegistered on GetIt { + Future unregisterIfRegistered() async { + if (!isRegistered()) return; + + await unregister(); + } +} diff --git a/AdminUi/apps/admin_ui/lib/utils/utils.dart b/AdminUi/apps/admin_ui/lib/utils/utils.dart new file mode 100644 index 0000000000..80e5db443b --- /dev/null +++ b/AdminUi/apps/admin_ui/lib/utils/utils.dart @@ -0,0 +1,2 @@ +export 'app_config.dart'; +export 'extensions.dart'; From ffa978880f88039a7b1ed0696dceb022af2f7763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Tue, 2 Apr 2024 16:59:22 +0200 Subject: [PATCH 29/43] fix: imports --- AdminUi/apps/admin_ui/lib/main.dart | 3 +-- AdminUi/apps/admin_ui/lib/screens/home_screen.dart | 2 +- AdminUi/apps/admin_ui/lib/screens/login_screen.dart | 7 ++----- .../admin_ui/lib/theme/{colors => }/color_schemes.dart | 0 .../admin_ui/lib/theme/{colors => }/custom_colors.dart | 0 AdminUi/apps/admin_ui/lib/theme/theme.dart | 2 ++ .../admin_ui/lib/{styles => utils}/widgets/app_title.dart | 0 .../{styles => utils}/widgets/custom_elevated_button.dart | 0 .../{styles => utils}/widgets/custom_styled_container.dart | 0 .../lib/{styles => utils}/widgets/custom_text_field.dart | 3 ++- AdminUi/apps/admin_ui/lib/utils/widgets/widgets.dart | 4 ++++ 11 files changed, 12 insertions(+), 9 deletions(-) rename AdminUi/apps/admin_ui/lib/theme/{colors => }/color_schemes.dart (100%) rename AdminUi/apps/admin_ui/lib/theme/{colors => }/custom_colors.dart (100%) create mode 100644 AdminUi/apps/admin_ui/lib/theme/theme.dart rename AdminUi/apps/admin_ui/lib/{styles => utils}/widgets/app_title.dart (100%) rename AdminUi/apps/admin_ui/lib/{styles => utils}/widgets/custom_elevated_button.dart (100%) rename AdminUi/apps/admin_ui/lib/{styles => utils}/widgets/custom_styled_container.dart (100%) rename AdminUi/apps/admin_ui/lib/{styles => utils}/widgets/custom_text_field.dart (95%) create mode 100644 AdminUi/apps/admin_ui/lib/utils/widgets/widgets.dart diff --git a/AdminUi/apps/admin_ui/lib/main.dart b/AdminUi/apps/admin_ui/lib/main.dart index aa70d89ca2..d362ac26c4 100644 --- a/AdminUi/apps/admin_ui/lib/main.dart +++ b/AdminUi/apps/admin_ui/lib/main.dart @@ -1,11 +1,10 @@ -import 'package:admin_ui/theme/colors/color_schemes.dart'; -import 'package:admin_ui/theme/colors/custom_colors.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'home/home.dart'; import 'screens/screens.dart'; import 'setup/setup_desktop.dart' if (dart.library.html) 'setup/setup_web.dart'; +import 'theme/theme.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); diff --git a/AdminUi/apps/admin_ui/lib/screens/home_screen.dart b/AdminUi/apps/admin_ui/lib/screens/home_screen.dart index 74fb299bf9..17dd31c58c 100644 --- a/AdminUi/apps/admin_ui/lib/screens/home_screen.dart +++ b/AdminUi/apps/admin_ui/lib/screens/home_screen.dart @@ -1,11 +1,11 @@ import 'package:admin_api_sdk/admin_api_sdk.dart'; -import 'package:admin_ui/styles/widgets/app_title.dart'; import 'package:flutter/material.dart'; import 'package:get_it/get_it.dart'; import 'package:go_router/go_router.dart'; import 'package:shared_preferences/shared_preferences.dart'; import '/utils/utils.dart'; +import '/utils/widgets/widgets.dart'; class HomeScreen extends StatefulWidget { final Widget child; diff --git a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart index f39c505918..218a62f240 100644 --- a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart +++ b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart @@ -1,15 +1,12 @@ import 'package:admin_api_sdk/admin_api_sdk.dart'; -import 'package:admin_ui/styles/widgets/app_title.dart'; -import 'package:admin_ui/styles/widgets/custom_elevated_button.dart'; -import 'package:admin_ui/styles/widgets/custom_styled_container.dart'; -import 'package:admin_ui/styles/widgets/custom_text_field.dart'; -import 'package:admin_ui/theme/colors/custom_colors.dart'; import 'package:flutter/material.dart'; import 'package:get_it/get_it.dart'; import 'package:go_router/go_router.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import '../theme/custom_colors.dart'; import '/utils/utils.dart'; +import '/utils/widgets/widgets.dart'; class LoginScreen extends StatefulWidget { const LoginScreen({super.key}); diff --git a/AdminUi/apps/admin_ui/lib/theme/colors/color_schemes.dart b/AdminUi/apps/admin_ui/lib/theme/color_schemes.dart similarity index 100% rename from AdminUi/apps/admin_ui/lib/theme/colors/color_schemes.dart rename to AdminUi/apps/admin_ui/lib/theme/color_schemes.dart diff --git a/AdminUi/apps/admin_ui/lib/theme/colors/custom_colors.dart b/AdminUi/apps/admin_ui/lib/theme/custom_colors.dart similarity index 100% rename from AdminUi/apps/admin_ui/lib/theme/colors/custom_colors.dart rename to AdminUi/apps/admin_ui/lib/theme/custom_colors.dart diff --git a/AdminUi/apps/admin_ui/lib/theme/theme.dart b/AdminUi/apps/admin_ui/lib/theme/theme.dart new file mode 100644 index 0000000000..bb6c7a2a0d --- /dev/null +++ b/AdminUi/apps/admin_ui/lib/theme/theme.dart @@ -0,0 +1,2 @@ +export 'color_schemes.dart'; +export 'custom_colors.dart'; diff --git a/AdminUi/apps/admin_ui/lib/styles/widgets/app_title.dart b/AdminUi/apps/admin_ui/lib/utils/widgets/app_title.dart similarity index 100% rename from AdminUi/apps/admin_ui/lib/styles/widgets/app_title.dart rename to AdminUi/apps/admin_ui/lib/utils/widgets/app_title.dart diff --git a/AdminUi/apps/admin_ui/lib/styles/widgets/custom_elevated_button.dart b/AdminUi/apps/admin_ui/lib/utils/widgets/custom_elevated_button.dart similarity index 100% rename from AdminUi/apps/admin_ui/lib/styles/widgets/custom_elevated_button.dart rename to AdminUi/apps/admin_ui/lib/utils/widgets/custom_elevated_button.dart diff --git a/AdminUi/apps/admin_ui/lib/styles/widgets/custom_styled_container.dart b/AdminUi/apps/admin_ui/lib/utils/widgets/custom_styled_container.dart similarity index 100% rename from AdminUi/apps/admin_ui/lib/styles/widgets/custom_styled_container.dart rename to AdminUi/apps/admin_ui/lib/utils/widgets/custom_styled_container.dart diff --git a/AdminUi/apps/admin_ui/lib/styles/widgets/custom_text_field.dart b/AdminUi/apps/admin_ui/lib/utils/widgets/custom_text_field.dart similarity index 95% rename from AdminUi/apps/admin_ui/lib/styles/widgets/custom_text_field.dart rename to AdminUi/apps/admin_ui/lib/utils/widgets/custom_text_field.dart index 30051088b2..5d3b7f5475 100644 --- a/AdminUi/apps/admin_ui/lib/styles/widgets/custom_text_field.dart +++ b/AdminUi/apps/admin_ui/lib/utils/widgets/custom_text_field.dart @@ -1,6 +1,7 @@ -import 'package:admin_ui/theme/colors/custom_colors.dart'; import 'package:flutter/material.dart'; +import '/theme/custom_colors.dart'; + class CustomTextField extends StatelessWidget { final TextEditingController controller; final FocusNode focusNode; diff --git a/AdminUi/apps/admin_ui/lib/utils/widgets/widgets.dart b/AdminUi/apps/admin_ui/lib/utils/widgets/widgets.dart new file mode 100644 index 0000000000..b6d807fe5a --- /dev/null +++ b/AdminUi/apps/admin_ui/lib/utils/widgets/widgets.dart @@ -0,0 +1,4 @@ +export 'app_title.dart'; +export 'custom_elevated_button.dart'; +export 'custom_styled_container.dart'; +export 'custom_text_field.dart'; From 60cd19b67d8adfc878d7bf88e2b3c0224653f01d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Tue, 2 Apr 2024 17:01:46 +0200 Subject: [PATCH 30/43] fix: make CustomColors easier accessible --- AdminUi/apps/admin_ui/lib/screens/login_screen.dart | 5 +---- AdminUi/apps/admin_ui/lib/utils/extensions.dart | 7 +++++++ .../apps/admin_ui/lib/utils/widgets/custom_text_field.dart | 7 +++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart index 218a62f240..f0f9e97624 100644 --- a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart +++ b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart @@ -4,7 +4,6 @@ import 'package:get_it/get_it.dart'; import 'package:go_router/go_router.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import '../theme/custom_colors.dart'; import '/utils/utils.dart'; import '/utils/widgets/widgets.dart'; @@ -39,8 +38,6 @@ class _LoginScreenState extends State { @override Widget build(BuildContext context) { - final customColors = Theme.of(context).extension(); - return Scaffold( appBar: AppBar( title: const AppTitle(), @@ -78,7 +75,7 @@ class _LoginScreenState extends State { isEnabled: _isButtonEnabled, onPressed: _login, backgroundColor: Theme.of(context).colorScheme.primary, - textColor: customColors?.onNeutralvariant, + textColor: context.customColors.onNeutralvariant, ), ], ), diff --git a/AdminUi/apps/admin_ui/lib/utils/extensions.dart b/AdminUi/apps/admin_ui/lib/utils/extensions.dart index aef82fefaf..62e2b675e6 100644 --- a/AdminUi/apps/admin_ui/lib/utils/extensions.dart +++ b/AdminUi/apps/admin_ui/lib/utils/extensions.dart @@ -1,5 +1,8 @@ +import 'package:flutter/material.dart'; import 'package:get_it/get_it.dart'; +import '/theme/theme.dart'; + extension UnregisterIfRegistered on GetIt { Future unregisterIfRegistered() async { if (!isRegistered()) return; @@ -7,3 +10,7 @@ extension UnregisterIfRegistered on GetIt { await unregister(); } } + +extension GetCustomColors on BuildContext { + CustomColors get customColors => Theme.of(this).extension()!; +} diff --git a/AdminUi/apps/admin_ui/lib/utils/widgets/custom_text_field.dart b/AdminUi/apps/admin_ui/lib/utils/widgets/custom_text_field.dart index 5d3b7f5475..85dc9c3732 100644 --- a/AdminUi/apps/admin_ui/lib/utils/widgets/custom_text_field.dart +++ b/AdminUi/apps/admin_ui/lib/utils/widgets/custom_text_field.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -import '/theme/custom_colors.dart'; +import '/utils/utils.dart'; class CustomTextField extends StatelessWidget { final TextEditingController controller; @@ -24,7 +24,6 @@ class CustomTextField extends StatelessWidget { @override Widget build(BuildContext context) { - final customColors = Theme.of(context).extension(); return TextField( controller: controller, focusNode: focusNode, @@ -32,10 +31,10 @@ class CustomTextField extends StatelessWidget { labelText: label, border: const OutlineInputBorder(), errorBorder: OutlineInputBorder( - borderSide: BorderSide(color: customColors?.error ?? Colors.red, width: 2), + borderSide: BorderSide(color: context.customColors.error ?? Colors.red, width: 2), ), focusedErrorBorder: OutlineInputBorder( - borderSide: BorderSide(color: customColors?.error ?? Colors.red, width: 2), + borderSide: BorderSide(color: context.customColors.error ?? Colors.red, width: 2), ), errorText: errorText, ), From f234bcd37e9890949ccbc9254c7f9e1d5c10d571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Tue, 2 Apr 2024 17:05:37 +0200 Subject: [PATCH 31/43] fix: make prettier --- AdminUi/apps/admin_ui/lib/{utils => core}/app_config.dart | 0 AdminUi/apps/admin_ui/lib/{utils/utils.dart => core/core.dart} | 1 + AdminUi/apps/admin_ui/lib/{utils => core}/extensions.dart | 2 +- AdminUi/apps/admin_ui/lib/{ => core}/theme/color_schemes.dart | 0 AdminUi/apps/admin_ui/lib/{ => core}/theme/custom_colors.dart | 0 AdminUi/apps/admin_ui/lib/{ => core}/theme/theme.dart | 0 .../apps/admin_ui/lib/{utils => core}/widgets/app_title.dart | 0 .../lib/{utils => core}/widgets/custom_elevated_button.dart | 0 .../lib/{utils => core}/widgets/custom_styled_container.dart | 0 .../lib/{utils => core}/widgets/custom_text_field.dart | 2 +- AdminUi/apps/admin_ui/lib/{utils => core}/widgets/widgets.dart | 0 AdminUi/apps/admin_ui/lib/main.dart | 2 +- AdminUi/apps/admin_ui/lib/screens/home_screen.dart | 3 +-- AdminUi/apps/admin_ui/lib/screens/login_screen.dart | 3 +-- AdminUi/apps/admin_ui/lib/setup/setup_desktop.dart | 2 +- AdminUi/apps/admin_ui/lib/setup/setup_web.dart | 2 +- 16 files changed, 8 insertions(+), 9 deletions(-) rename AdminUi/apps/admin_ui/lib/{utils => core}/app_config.dart (100%) rename AdminUi/apps/admin_ui/lib/{utils/utils.dart => core/core.dart} (62%) rename AdminUi/apps/admin_ui/lib/{utils => core}/extensions.dart (93%) rename AdminUi/apps/admin_ui/lib/{ => core}/theme/color_schemes.dart (100%) rename AdminUi/apps/admin_ui/lib/{ => core}/theme/custom_colors.dart (100%) rename AdminUi/apps/admin_ui/lib/{ => core}/theme/theme.dart (100%) rename AdminUi/apps/admin_ui/lib/{utils => core}/widgets/app_title.dart (100%) rename AdminUi/apps/admin_ui/lib/{utils => core}/widgets/custom_elevated_button.dart (100%) rename AdminUi/apps/admin_ui/lib/{utils => core}/widgets/custom_styled_container.dart (100%) rename AdminUi/apps/admin_ui/lib/{utils => core}/widgets/custom_text_field.dart (97%) rename AdminUi/apps/admin_ui/lib/{utils => core}/widgets/widgets.dart (100%) diff --git a/AdminUi/apps/admin_ui/lib/utils/app_config.dart b/AdminUi/apps/admin_ui/lib/core/app_config.dart similarity index 100% rename from AdminUi/apps/admin_ui/lib/utils/app_config.dart rename to AdminUi/apps/admin_ui/lib/core/app_config.dart diff --git a/AdminUi/apps/admin_ui/lib/utils/utils.dart b/AdminUi/apps/admin_ui/lib/core/core.dart similarity index 62% rename from AdminUi/apps/admin_ui/lib/utils/utils.dart rename to AdminUi/apps/admin_ui/lib/core/core.dart index 80e5db443b..10a51ca758 100644 --- a/AdminUi/apps/admin_ui/lib/utils/utils.dart +++ b/AdminUi/apps/admin_ui/lib/core/core.dart @@ -1,2 +1,3 @@ export 'app_config.dart'; export 'extensions.dart'; +export 'widgets/widgets.dart'; diff --git a/AdminUi/apps/admin_ui/lib/utils/extensions.dart b/AdminUi/apps/admin_ui/lib/core/extensions.dart similarity index 93% rename from AdminUi/apps/admin_ui/lib/utils/extensions.dart rename to AdminUi/apps/admin_ui/lib/core/extensions.dart index 62e2b675e6..4706e2d4d5 100644 --- a/AdminUi/apps/admin_ui/lib/utils/extensions.dart +++ b/AdminUi/apps/admin_ui/lib/core/extensions.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:get_it/get_it.dart'; -import '/theme/theme.dart'; +import 'theme/theme.dart'; extension UnregisterIfRegistered on GetIt { Future unregisterIfRegistered() async { diff --git a/AdminUi/apps/admin_ui/lib/theme/color_schemes.dart b/AdminUi/apps/admin_ui/lib/core/theme/color_schemes.dart similarity index 100% rename from AdminUi/apps/admin_ui/lib/theme/color_schemes.dart rename to AdminUi/apps/admin_ui/lib/core/theme/color_schemes.dart diff --git a/AdminUi/apps/admin_ui/lib/theme/custom_colors.dart b/AdminUi/apps/admin_ui/lib/core/theme/custom_colors.dart similarity index 100% rename from AdminUi/apps/admin_ui/lib/theme/custom_colors.dart rename to AdminUi/apps/admin_ui/lib/core/theme/custom_colors.dart diff --git a/AdminUi/apps/admin_ui/lib/theme/theme.dart b/AdminUi/apps/admin_ui/lib/core/theme/theme.dart similarity index 100% rename from AdminUi/apps/admin_ui/lib/theme/theme.dart rename to AdminUi/apps/admin_ui/lib/core/theme/theme.dart diff --git a/AdminUi/apps/admin_ui/lib/utils/widgets/app_title.dart b/AdminUi/apps/admin_ui/lib/core/widgets/app_title.dart similarity index 100% rename from AdminUi/apps/admin_ui/lib/utils/widgets/app_title.dart rename to AdminUi/apps/admin_ui/lib/core/widgets/app_title.dart diff --git a/AdminUi/apps/admin_ui/lib/utils/widgets/custom_elevated_button.dart b/AdminUi/apps/admin_ui/lib/core/widgets/custom_elevated_button.dart similarity index 100% rename from AdminUi/apps/admin_ui/lib/utils/widgets/custom_elevated_button.dart rename to AdminUi/apps/admin_ui/lib/core/widgets/custom_elevated_button.dart diff --git a/AdminUi/apps/admin_ui/lib/utils/widgets/custom_styled_container.dart b/AdminUi/apps/admin_ui/lib/core/widgets/custom_styled_container.dart similarity index 100% rename from AdminUi/apps/admin_ui/lib/utils/widgets/custom_styled_container.dart rename to AdminUi/apps/admin_ui/lib/core/widgets/custom_styled_container.dart diff --git a/AdminUi/apps/admin_ui/lib/utils/widgets/custom_text_field.dart b/AdminUi/apps/admin_ui/lib/core/widgets/custom_text_field.dart similarity index 97% rename from AdminUi/apps/admin_ui/lib/utils/widgets/custom_text_field.dart rename to AdminUi/apps/admin_ui/lib/core/widgets/custom_text_field.dart index 85dc9c3732..4f69f9c031 100644 --- a/AdminUi/apps/admin_ui/lib/utils/widgets/custom_text_field.dart +++ b/AdminUi/apps/admin_ui/lib/core/widgets/custom_text_field.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -import '/utils/utils.dart'; +import '../extensions.dart'; class CustomTextField extends StatelessWidget { final TextEditingController controller; diff --git a/AdminUi/apps/admin_ui/lib/utils/widgets/widgets.dart b/AdminUi/apps/admin_ui/lib/core/widgets/widgets.dart similarity index 100% rename from AdminUi/apps/admin_ui/lib/utils/widgets/widgets.dart rename to AdminUi/apps/admin_ui/lib/core/widgets/widgets.dart diff --git a/AdminUi/apps/admin_ui/lib/main.dart b/AdminUi/apps/admin_ui/lib/main.dart index d362ac26c4..f207877f93 100644 --- a/AdminUi/apps/admin_ui/lib/main.dart +++ b/AdminUi/apps/admin_ui/lib/main.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; +import 'core/theme/theme.dart'; import 'home/home.dart'; import 'screens/screens.dart'; import 'setup/setup_desktop.dart' if (dart.library.html) 'setup/setup_web.dart'; -import 'theme/theme.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); diff --git a/AdminUi/apps/admin_ui/lib/screens/home_screen.dart b/AdminUi/apps/admin_ui/lib/screens/home_screen.dart index 17dd31c58c..bda4506389 100644 --- a/AdminUi/apps/admin_ui/lib/screens/home_screen.dart +++ b/AdminUi/apps/admin_ui/lib/screens/home_screen.dart @@ -4,8 +4,7 @@ import 'package:get_it/get_it.dart'; import 'package:go_router/go_router.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import '/utils/utils.dart'; -import '/utils/widgets/widgets.dart'; +import '/core/core.dart'; class HomeScreen extends StatefulWidget { final Widget child; diff --git a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart index f0f9e97624..e7ebf41cb6 100644 --- a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart +++ b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart @@ -4,8 +4,7 @@ import 'package:get_it/get_it.dart'; import 'package:go_router/go_router.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import '/utils/utils.dart'; -import '/utils/widgets/widgets.dart'; +import '/core/core.dart'; class LoginScreen extends StatefulWidget { const LoginScreen({super.key}); diff --git a/AdminUi/apps/admin_ui/lib/setup/setup_desktop.dart b/AdminUi/apps/admin_ui/lib/setup/setup_desktop.dart index 754f64f620..9a341a2403 100644 --- a/AdminUi/apps/admin_ui/lib/setup/setup_desktop.dart +++ b/AdminUi/apps/admin_ui/lib/setup/setup_desktop.dart @@ -4,7 +4,7 @@ import 'dart:ui'; import 'package:get_it/get_it.dart'; import 'package:window_size/window_size.dart'; -import '/utils/utils.dart'; +import '/core/core.dart'; Future setup() async { if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) { diff --git a/AdminUi/apps/admin_ui/lib/setup/setup_web.dart b/AdminUi/apps/admin_ui/lib/setup/setup_web.dart index 1766df17bf..05f6e02659 100644 --- a/AdminUi/apps/admin_ui/lib/setup/setup_web.dart +++ b/AdminUi/apps/admin_ui/lib/setup/setup_web.dart @@ -1,6 +1,6 @@ import 'package:get_it/get_it.dart'; -import '/utils/app_config.dart'; +import '/core/app_config.dart'; Future setup() async { GetIt.I.registerSingleton(AppConfig(baseUrl: '')); From 71564770ecd53807edf554bd1640f8960ee5364a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Tue, 2 Apr 2024 17:08:43 +0200 Subject: [PATCH 32/43] feat: add gaps --- AdminUi/apps/admin_ui/lib/core/constants.dart | 19 +++++++++++++++++++ AdminUi/apps/admin_ui/lib/core/core.dart | 1 + .../admin_ui/lib/core/widgets/app_title.dart | 4 +++- .../admin_ui/lib/screens/home_screen.dart | 2 +- .../admin_ui/lib/screens/login_screen.dart | 2 +- .../admin_ui/lib/screens/splash_screens.dart | 4 +++- 6 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 AdminUi/apps/admin_ui/lib/core/constants.dart diff --git a/AdminUi/apps/admin_ui/lib/core/constants.dart b/AdminUi/apps/admin_ui/lib/core/constants.dart new file mode 100644 index 0000000000..be707b42cd --- /dev/null +++ b/AdminUi/apps/admin_ui/lib/core/constants.dart @@ -0,0 +1,19 @@ +import 'package:flutter/widgets.dart'; + +class Gaps { + Gaps._(); + + static const SizedBox h4 = SizedBox(height: 4); + static const SizedBox h8 = SizedBox(height: 8); + static const SizedBox h16 = SizedBox(height: 16); + static const SizedBox h24 = SizedBox(height: 24); + static const SizedBox h32 = SizedBox(height: 32); + static const SizedBox h40 = SizedBox(height: 40); + + static const SizedBox w4 = SizedBox(width: 4); + static const SizedBox w8 = SizedBox(width: 8); + static const SizedBox w16 = SizedBox(width: 16); + static const SizedBox w24 = SizedBox(width: 24); + static const SizedBox w32 = SizedBox(width: 32); + static const SizedBox w40 = SizedBox(width: 40); +} diff --git a/AdminUi/apps/admin_ui/lib/core/core.dart b/AdminUi/apps/admin_ui/lib/core/core.dart index 10a51ca758..2a213e1e45 100644 --- a/AdminUi/apps/admin_ui/lib/core/core.dart +++ b/AdminUi/apps/admin_ui/lib/core/core.dart @@ -1,3 +1,4 @@ export 'app_config.dart'; +export 'constants.dart'; export 'extensions.dart'; export 'widgets/widgets.dart'; diff --git a/AdminUi/apps/admin_ui/lib/core/widgets/app_title.dart b/AdminUi/apps/admin_ui/lib/core/widgets/app_title.dart index 4b43a2d99b..d997f7b314 100644 --- a/AdminUi/apps/admin_ui/lib/core/widgets/app_title.dart +++ b/AdminUi/apps/admin_ui/lib/core/widgets/app_title.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; +import '../constants.dart'; + class AppTitle extends StatelessWidget { const AppTitle({super.key}); @@ -14,7 +16,7 @@ class AppTitle extends StatelessWidget { width: 30, height: 30, ), - const SizedBox(width: 10), + Gaps.w8, RichText( text: TextSpan( children: [ diff --git a/AdminUi/apps/admin_ui/lib/screens/home_screen.dart b/AdminUi/apps/admin_ui/lib/screens/home_screen.dart index bda4506389..3e6499f4c7 100644 --- a/AdminUi/apps/admin_ui/lib/screens/home_screen.dart +++ b/AdminUi/apps/admin_ui/lib/screens/home_screen.dart @@ -34,7 +34,7 @@ class _HomeScreenState extends State { ), actions: [ IconButton(icon: const Icon(Icons.logout), onPressed: _logout), - const SizedBox(width: 10), + Gaps.w8, ], ), body: Row( diff --git a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart index e7ebf41cb6..e2fef9c0f2 100644 --- a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart +++ b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart @@ -68,7 +68,7 @@ class _LoginScreenState extends State { onSubmitted: (_) => _login(), ), ), - const SizedBox(height: 20), + Gaps.h16, CustomElevatedButton( text: 'Login', isEnabled: _isButtonEnabled, diff --git a/AdminUi/apps/admin_ui/lib/screens/splash_screens.dart b/AdminUi/apps/admin_ui/lib/screens/splash_screens.dart index 0fe6ab31ca..ab80f5e864 100644 --- a/AdminUi/apps/admin_ui/lib/screens/splash_screens.dart +++ b/AdminUi/apps/admin_ui/lib/screens/splash_screens.dart @@ -6,6 +6,8 @@ import 'package:get_it/get_it.dart'; import 'package:go_router/go_router.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import '/core/core.dart'; + class SplashScreen extends StatefulWidget { const SplashScreen({super.key}); @@ -29,7 +31,7 @@ class _SplashScreenState extends State { mainAxisSize: MainAxisSize.min, children: [ SvgPicture.asset('assets/logo.svg', width: 200, height: 200), - const SizedBox(height: 40), + Gaps.h40, const SizedBox(width: 300, child: LinearProgressIndicator()), ], ), From 9bfbc2a2577700f68d57ed230a26983948b78161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Tue, 2 Apr 2024 17:09:28 +0200 Subject: [PATCH 33/43] fix: rename file --- AdminUi/apps/admin_ui/lib/screens/screens.dart | 2 +- .../lib/screens/{splash_screens.dart => splash_screen.dart} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename AdminUi/apps/admin_ui/lib/screens/{splash_screens.dart => splash_screen.dart} (100%) diff --git a/AdminUi/apps/admin_ui/lib/screens/screens.dart b/AdminUi/apps/admin_ui/lib/screens/screens.dart index 649399d610..22c5a99985 100644 --- a/AdminUi/apps/admin_ui/lib/screens/screens.dart +++ b/AdminUi/apps/admin_ui/lib/screens/screens.dart @@ -1,3 +1,3 @@ export 'home_screen.dart'; export 'login_screen.dart'; -export 'splash_screens.dart'; +export 'splash_screen.dart'; diff --git a/AdminUi/apps/admin_ui/lib/screens/splash_screens.dart b/AdminUi/apps/admin_ui/lib/screens/splash_screen.dart similarity index 100% rename from AdminUi/apps/admin_ui/lib/screens/splash_screens.dart rename to AdminUi/apps/admin_ui/lib/screens/splash_screen.dart From d83ba82bb2fdd328318a2d02a796905b3c47cd57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Tue, 2 Apr 2024 17:32:52 +0200 Subject: [PATCH 34/43] refactor: remove CustomX, make whole logic with one variable --- .../core/widgets/custom_elevated_button.dart | 38 --------- .../core/widgets/custom_styled_container.dart | 25 ------ .../lib/core/widgets/custom_text_field.dart | 46 ---------- .../admin_ui/lib/core/widgets/widgets.dart | 3 - AdminUi/apps/admin_ui/lib/main.dart | 1 + .../admin_ui/lib/screens/login_screen.dart | 83 ++++++++++--------- 6 files changed, 44 insertions(+), 152 deletions(-) delete mode 100644 AdminUi/apps/admin_ui/lib/core/widgets/custom_elevated_button.dart delete mode 100644 AdminUi/apps/admin_ui/lib/core/widgets/custom_styled_container.dart delete mode 100644 AdminUi/apps/admin_ui/lib/core/widgets/custom_text_field.dart diff --git a/AdminUi/apps/admin_ui/lib/core/widgets/custom_elevated_button.dart b/AdminUi/apps/admin_ui/lib/core/widgets/custom_elevated_button.dart deleted file mode 100644 index d96c82ad06..0000000000 --- a/AdminUi/apps/admin_ui/lib/core/widgets/custom_elevated_button.dart +++ /dev/null @@ -1,38 +0,0 @@ -import 'package:flutter/material.dart'; - -class CustomElevatedButton extends StatelessWidget { - final String text; - final bool isEnabled; - final VoidCallback? onPressed; - final Color? backgroundColor; - final Color? textColor; - - const CustomElevatedButton({ - required this.text, - required this.isEnabled, - this.onPressed, - this.backgroundColor, - this.textColor, - super.key, - }); - - @override - Widget build(BuildContext context) { - return SizedBox( - width: double.infinity, - height: 40, - child: ElevatedButton( - onPressed: isEnabled ? onPressed : null, - style: ButtonStyle( - backgroundColor: MaterialStatePropertyAll( - isEnabled ? backgroundColor ?? Theme.of(context).colorScheme.primary : null, - ), - ), - child: Text( - text, - style: TextStyle(color: isEnabled ? textColor ?? Colors.white : null), - ), - ), - ); - } -} diff --git a/AdminUi/apps/admin_ui/lib/core/widgets/custom_styled_container.dart b/AdminUi/apps/admin_ui/lib/core/widgets/custom_styled_container.dart deleted file mode 100644 index 3e2f33f3d9..0000000000 --- a/AdminUi/apps/admin_ui/lib/core/widgets/custom_styled_container.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'package:flutter/material.dart'; - -class CustomStyledContainer extends StatelessWidget { - final Widget child; - final double width; - final EdgeInsetsGeometry padding; - - const CustomStyledContainer({ - required this.child, - this.width = 400.0, - this.padding = const EdgeInsets.all(25), - super.key, - }); - - @override - Widget build(BuildContext context) { - return SizedBox( - width: width, - child: Padding( - padding: padding, - child: child, - ), - ); - } -} diff --git a/AdminUi/apps/admin_ui/lib/core/widgets/custom_text_field.dart b/AdminUi/apps/admin_ui/lib/core/widgets/custom_text_field.dart deleted file mode 100644 index 4f69f9c031..0000000000 --- a/AdminUi/apps/admin_ui/lib/core/widgets/custom_text_field.dart +++ /dev/null @@ -1,46 +0,0 @@ -import 'package:flutter/material.dart'; - -import '../extensions.dart'; - -class CustomTextField extends StatelessWidget { - final TextEditingController controller; - final FocusNode focusNode; - final String label; - final bool obscureText; - final String? errorText; - final void Function(String) onChanged; - final void Function(String) onSubmitted; - - const CustomTextField({ - required this.controller, - required this.focusNode, - required this.label, - required this.onChanged, - required this.onSubmitted, - this.obscureText = false, - this.errorText, - super.key, - }); - - @override - Widget build(BuildContext context) { - return TextField( - controller: controller, - focusNode: focusNode, - decoration: InputDecoration( - labelText: label, - border: const OutlineInputBorder(), - errorBorder: OutlineInputBorder( - borderSide: BorderSide(color: context.customColors.error ?? Colors.red, width: 2), - ), - focusedErrorBorder: OutlineInputBorder( - borderSide: BorderSide(color: context.customColors.error ?? Colors.red, width: 2), - ), - errorText: errorText, - ), - obscureText: obscureText, - onChanged: onChanged, - onSubmitted: onSubmitted, - ); - } -} diff --git a/AdminUi/apps/admin_ui/lib/core/widgets/widgets.dart b/AdminUi/apps/admin_ui/lib/core/widgets/widgets.dart index b6d807fe5a..bdfa30afdc 100644 --- a/AdminUi/apps/admin_ui/lib/core/widgets/widgets.dart +++ b/AdminUi/apps/admin_ui/lib/core/widgets/widgets.dart @@ -1,4 +1 @@ export 'app_title.dart'; -export 'custom_elevated_button.dart'; -export 'custom_styled_container.dart'; -export 'custom_text_field.dart'; diff --git a/AdminUi/apps/admin_ui/lib/main.dart b/AdminUi/apps/admin_ui/lib/main.dart index f207877f93..88ab024bce 100644 --- a/AdminUi/apps/admin_ui/lib/main.dart +++ b/AdminUi/apps/admin_ui/lib/main.dart @@ -70,6 +70,7 @@ class AdminUiApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp.router( + themeMode: ThemeMode.light, theme: ThemeData( useMaterial3: true, colorScheme: lightColorScheme, diff --git a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart index e2fef9c0f2..b8430eb700 100644 --- a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart +++ b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart @@ -17,13 +17,12 @@ class _LoginScreenState extends State { final _apiKeyController = TextEditingController(); final _apiKeyFocusNode = FocusNode(); - bool _isButtonEnabled = false; - bool _isApiKeyValid = false; - bool _hasAttemptedLogin = false; + bool? _isApiKeyValid; @override void initState() { super.initState(); + _apiKeyFocusNode.requestFocus(); } @@ -45,38 +44,46 @@ class _LoginScreenState extends State { ), ), body: Center( - child: Card( - child: CustomStyledContainer( - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - SizedBox( - height: 100, - child: CustomTextField( - controller: _apiKeyController, - focusNode: _apiKeyFocusNode, - label: 'API Key', - obscureText: true, - errorText: (_hasAttemptedLogin && !_isApiKeyValid) ? 'Invalid API Key' : null, - onChanged: (text) { - setState(() { - _isButtonEnabled = text.isNotEmpty; - _hasAttemptedLogin = false; - _isApiKeyValid = false; - }); - }, - onSubmitted: (_) => _login(), + child: SizedBox( + width: 400, + child: Card( + child: Padding( + padding: const EdgeInsets.all(25), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + SizedBox( + height: 100, + child: TextField( + controller: _apiKeyController, + focusNode: _apiKeyFocusNode, + decoration: InputDecoration( + labelText: 'API Key', + border: const OutlineInputBorder(), + errorText: (_isApiKeyValid == false) ? 'Invalid API Key' : null, + ), + obscureText: true, + onChanged: (text) { + if (_isApiKeyValid == null) return; + + setState(() { + _isApiKeyValid = null; + }); + }, + onSubmitted: (_) => _login(), + ), + ), + Gaps.h16, + SizedBox( + height: 40, + width: double.infinity, + child: FilledButton( + onPressed: _apiKeyController.text.isNotEmpty ? _login : null, + child: const Text('Login'), + ), ), - ), - Gaps.h16, - CustomElevatedButton( - text: 'Login', - isEnabled: _isButtonEnabled, - onPressed: _login, - backgroundColor: Theme.of(context).colorScheme.primary, - textColor: context.customColors.onNeutralvariant, - ), - ], + ], + ), ), ), ), @@ -86,19 +93,15 @@ class _LoginScreenState extends State { } Future _login() async { - _hasAttemptedLogin = true; final apiKey = _apiKeyController.text.trim(); if (apiKey.isEmpty) return; final baseUrl = GetIt.I().baseUrl; - _isApiKeyValid = await AdminApiClient.validateApiKey(baseUrl: baseUrl, apiKey: apiKey); + final isApiKeyValid = await AdminApiClient.validateApiKey(baseUrl: baseUrl, apiKey: apiKey); if (!mounted) return; - if (!_isApiKeyValid) { - setState(() {}); - return; - } + if (!isApiKeyValid) return setState(() => _isApiKeyValid = false); final sp = await SharedPreferences.getInstance(); await sp.setString('api_key', apiKey); From 38c35af77752c52f60267d66d117102cfc6c38d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Wed, 3 Apr 2024 09:10:40 +0200 Subject: [PATCH 35/43] fix: bool logic --- AdminUi/apps/admin_ui/lib/screens/login_screen.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart index b8430eb700..955d88abea 100644 --- a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart +++ b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart @@ -64,7 +64,7 @@ class _LoginScreenState extends State { ), obscureText: true, onChanged: (text) { - if (_isApiKeyValid == null) return; + if (_isApiKeyValid != null) return; setState(() { _isApiKeyValid = null; From 8a98917dbfcd90eea300876b844a42e535936f49 Mon Sep 17 00:00:00 2001 From: Timo Notheisen Date: Wed, 3 Apr 2024 09:23:21 +0200 Subject: [PATCH 36/43] ci: add jkoenig134 as codeowner --- .github/CODEOWNERS | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 932f80a1cf..5e72fda3e8 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1,2 @@ * @tnotheis +* @jkoenig134 From ad2497e584b85c04e2d9c9071a9fbef413517605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Wed, 3 Apr 2024 09:42:14 +0200 Subject: [PATCH 37/43] chore: remove accidentally committet code --- AdminUi/apps/admin_ui/lib/main.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/AdminUi/apps/admin_ui/lib/main.dart b/AdminUi/apps/admin_ui/lib/main.dart index 88ab024bce..f207877f93 100644 --- a/AdminUi/apps/admin_ui/lib/main.dart +++ b/AdminUi/apps/admin_ui/lib/main.dart @@ -70,7 +70,6 @@ class AdminUiApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp.router( - themeMode: ThemeMode.light, theme: ThemeData( useMaterial3: true, colorScheme: lightColorScheme, From 665e072501d0cf1b3be2af260b318c61026bd5b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Wed, 3 Apr 2024 09:48:53 +0200 Subject: [PATCH 38/43] fix: undo change --- AdminUi/apps/admin_ui/lib/screens/login_screen.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart index 955d88abea..b8430eb700 100644 --- a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart +++ b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart @@ -64,7 +64,7 @@ class _LoginScreenState extends State { ), obscureText: true, onChanged: (text) { - if (_isApiKeyValid != null) return; + if (_isApiKeyValid == null) return; setState(() { _isApiKeyValid = null; From cda655abe4800d6d5409224fa55ce7efb075949f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Wed, 3 Apr 2024 10:20:49 +0200 Subject: [PATCH 39/43] refactor: simplify login screen --- .../admin_ui/lib/screens/login_screen.dart | 49 +++++++++---------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart index b8430eb700..77a2d7a39c 100644 --- a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart +++ b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart @@ -52,35 +52,30 @@ class _LoginScreenState extends State { child: Column( mainAxisSize: MainAxisSize.min, children: [ - SizedBox( - height: 100, - child: TextField( - controller: _apiKeyController, - focusNode: _apiKeyFocusNode, - decoration: InputDecoration( - labelText: 'API Key', - border: const OutlineInputBorder(), - errorText: (_isApiKeyValid == false) ? 'Invalid API Key' : null, - ), - obscureText: true, - onChanged: (text) { - if (_isApiKeyValid == null) return; - - setState(() { - _isApiKeyValid = null; - }); - }, - onSubmitted: (_) => _login(), + TextField( + controller: _apiKeyController, + focusNode: _apiKeyFocusNode, + decoration: InputDecoration( + labelText: 'API Key', + border: const OutlineInputBorder(), + errorText: (_isApiKeyValid == false) ? 'Invalid API Key' : null, + helperText: '', ), + obscureText: true, + onChanged: (text) { + if (_isApiKeyValid == null) return; + + setState(() { + _isApiKeyValid = null; + }); + }, + onSubmitted: (_) => _login(), ), - Gaps.h16, - SizedBox( - height: 40, - width: double.infinity, - child: FilledButton( - onPressed: _apiKeyController.text.isNotEmpty ? _login : null, - child: const Text('Login'), - ), + Gaps.h24, + FilledButton( + style: FilledButton.styleFrom(minimumSize: const Size.fromHeight(45)), + onPressed: _apiKeyController.text.isNotEmpty ? _login : null, + child: const Text('Login'), ), ], ), From 900b5a92901727954a0374e7f6c1401339a5547f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Wed, 3 Apr 2024 10:42:24 +0200 Subject: [PATCH 40/43] refactor: simplify app title --- .../admin_ui/lib/core/widgets/app_title.dart | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/AdminUi/apps/admin_ui/lib/core/widgets/app_title.dart b/AdminUi/apps/admin_ui/lib/core/widgets/app_title.dart index d997f7b314..ad94acc730 100644 --- a/AdminUi/apps/admin_ui/lib/core/widgets/app_title.dart +++ b/AdminUi/apps/admin_ui/lib/core/widgets/app_title.dart @@ -8,6 +8,8 @@ class AppTitle extends StatelessWidget { @override Widget build(BuildContext context) { + const textStyle = TextStyle(fontSize: 25); + return Row( mainAxisSize: MainAxisSize.min, children: [ @@ -17,24 +19,11 @@ class AppTitle extends StatelessWidget { height: 30, ), Gaps.w8, - RichText( - text: TextSpan( + Text.rich( + TextSpan( children: [ - TextSpan( - text: 'enmeshed', - style: TextStyle( - fontWeight: FontWeight.bold, - color: Theme.of(context).colorScheme.scrim, - fontSize: 25, - ), - ), - TextSpan( - text: ' Admin UI', - style: TextStyle( - color: Theme.of(context).colorScheme.scrim, - fontSize: 25, - ), - ), + TextSpan(text: 'enmeshed', style: textStyle.copyWith(fontWeight: FontWeight.bold)), + const TextSpan(text: ' Admin UI', style: textStyle), ], ), ), From 7bbba1a34453b703013093c4b7254ce3d205d789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Wed, 3 Apr 2024 10:45:32 +0200 Subject: [PATCH 41/43] refactor: PR comments --- .../admin_ui/lib/screens/login_screen.dart | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart index 77a2d7a39c..9a94abaf63 100644 --- a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart +++ b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart @@ -39,9 +39,8 @@ class _LoginScreenState extends State { return Scaffold( appBar: AppBar( title: const AppTitle(), - leading: const SizedBox( - width: 40, - ), + centerTitle: false, + leading: Gaps.w40, ), body: Center( child: SizedBox( @@ -58,16 +57,14 @@ class _LoginScreenState extends State { decoration: InputDecoration( labelText: 'API Key', border: const OutlineInputBorder(), - errorText: (_isApiKeyValid == false) ? 'Invalid API Key' : null, + errorText: _isApiKeyValid == false ? 'Invalid API Key' : null, helperText: '', ), obscureText: true, - onChanged: (text) { - if (_isApiKeyValid == null) return; + onChanged: (_) { + if (_isApiKeyValid == null) return setState(() {}); - setState(() { - _isApiKeyValid = null; - }); + setState(() => _isApiKeyValid = null); }, onSubmitted: (_) => _login(), ), @@ -88,7 +85,7 @@ class _LoginScreenState extends State { } Future _login() async { - final apiKey = _apiKeyController.text.trim(); + final apiKey = _apiKeyController.text; if (apiKey.isEmpty) return; final baseUrl = GetIt.I().baseUrl; @@ -96,7 +93,13 @@ class _LoginScreenState extends State { if (!mounted) return; - if (!isApiKeyValid) return setState(() => _isApiKeyValid = false); + if (!isApiKeyValid) { + setState(() => _isApiKeyValid = false); + + _apiKeyFocusNode.requestFocus(); + + return; + } final sp = await SharedPreferences.getInstance(); await sp.setString('api_key', apiKey); From dde4624cab701fc054f6bbce372c892bb8dd14ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Wed, 3 Apr 2024 10:48:03 +0200 Subject: [PATCH 42/43] chore: inline svg picture --- AdminUi/apps/admin_ui/lib/core/widgets/app_title.dart | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/AdminUi/apps/admin_ui/lib/core/widgets/app_title.dart b/AdminUi/apps/admin_ui/lib/core/widgets/app_title.dart index ad94acc730..92bd697b72 100644 --- a/AdminUi/apps/admin_ui/lib/core/widgets/app_title.dart +++ b/AdminUi/apps/admin_ui/lib/core/widgets/app_title.dart @@ -13,11 +13,7 @@ class AppTitle extends StatelessWidget { return Row( mainAxisSize: MainAxisSize.min, children: [ - SvgPicture.asset( - 'assets/logo.svg', - width: 30, - height: 30, - ), + SvgPicture.asset('assets/logo.svg', width: 30, height: 30), Gaps.w8, Text.rich( TextSpan( From 7b17855ed1fd4da7242686727a71b338224fc151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Wed, 3 Apr 2024 10:58:08 +0200 Subject: [PATCH 43/43] chore: make multi line params last --- AdminUi/apps/admin_ui/lib/screens/login_screen.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart index 9a94abaf63..6db960862d 100644 --- a/AdminUi/apps/admin_ui/lib/screens/login_screen.dart +++ b/AdminUi/apps/admin_ui/lib/screens/login_screen.dart @@ -37,6 +37,7 @@ class _LoginScreenState extends State { @override Widget build(BuildContext context) { return Scaffold( + backgroundColor: Theme.of(context).colorScheme.inversePrimary, appBar: AppBar( title: const AppTitle(), centerTitle: false, @@ -54,13 +55,13 @@ class _LoginScreenState extends State { TextField( controller: _apiKeyController, focusNode: _apiKeyFocusNode, + obscureText: true, decoration: InputDecoration( labelText: 'API Key', border: const OutlineInputBorder(), errorText: _isApiKeyValid == false ? 'Invalid API Key' : null, helperText: '', ), - obscureText: true, onChanged: (_) { if (_isApiKeyValid == null) return setState(() {}); @@ -80,7 +81,6 @@ class _LoginScreenState extends State { ), ), ), - backgroundColor: Theme.of(context).colorScheme.inversePrimary, ); }