Code improvements

This commit is contained in:
Juan Gilsanz Polo
2025-04-03 22:26:14 +02:00
parent 7982644c23
commit 93ebb1de40
17 changed files with 114 additions and 107 deletions

View File

@@ -12,5 +12,6 @@
"Linkding", "Linkding",
"linkdy", "linkdy",
"Linkdy" "Linkdy"
] ],
"cSpell.language": "en,es,tr",
} }

View File

@@ -208,14 +208,14 @@ class _ConnectForm extends ConsumerWidget {
onPressed: provider.testConnection == null ? () => ref.read(connectProvider.notifier).testConnection() : null, onPressed: provider.testConnection == null ? () => ref.read(connectProvider.notifier).testConnection() : null,
style: ButtonStyle( style: ButtonStyle(
foregroundColor: provider.testConnection == LoadStatus.loaded foregroundColor: provider.testConnection == LoadStatus.loaded
? const MaterialStatePropertyAll(Colors.green) ? const WidgetStatePropertyAll(Colors.green)
: provider.testConnection == LoadStatus.error : provider.testConnection == LoadStatus.error
? const MaterialStatePropertyAll(Colors.red) ? const WidgetStatePropertyAll(Colors.red)
: null, : null,
backgroundColor: provider.testConnection == LoadStatus.loaded backgroundColor: provider.testConnection == LoadStatus.loaded
? MaterialStatePropertyAll(Colors.green.withOpacity(0.15)) ? WidgetStatePropertyAll(Colors.green.withOpacity(0.15))
: provider.testConnection == LoadStatus.error : provider.testConnection == LoadStatus.error
? MaterialStatePropertyAll(Colors.red.withOpacity(0.15)) ? WidgetStatePropertyAll(Colors.red.withOpacity(0.15))
: null, : null,
), ),
child: Row( child: Row(

View File

@@ -15,7 +15,7 @@ class ColorItem extends StatelessWidget {
required this.color, required this.color,
required this.numericValue, required this.numericValue,
required this.selectedValue, required this.selectedValue,
required this.onChanged required this.onChanged,
}); });
@override @override
@@ -23,7 +23,7 @@ class ColorItem extends StatelessWidget {
return Padding( return Padding(
padding: index == 0 padding: index == 0
? const EdgeInsets.only(top: 10, right: 10, bottom: 10) ? const EdgeInsets.only(top: 10, right: 10, bottom: 10)
: index == total-1 : index == total - 1
? const EdgeInsets.only(top: 10, bottom: 10, left: 10) ? const EdgeInsets.only(top: 10, bottom: 10, left: 10)
: const EdgeInsets.all(10), : const EdgeInsets.all(10),
child: Material( child: Material(
@@ -31,13 +31,13 @@ class ColorItem extends StatelessWidget {
child: InkWell( child: InkWell(
onTap: () => onChanged(numericValue), onTap: () => onChanged(numericValue),
borderRadius: BorderRadius.circular(50), borderRadius: BorderRadius.circular(50),
overlayColor: const MaterialStatePropertyAll(Colors.grey), overlayColor: const WidgetStatePropertyAll(Colors.grey),
child: Container( child: Container(
width: 50, width: 50,
height: 50, height: 50,
decoration: BoxDecoration( decoration: BoxDecoration(
color: color, color: color,
borderRadius: BorderRadius.circular(50) borderRadius: BorderRadius.circular(50),
), ),
child: AnimatedOpacity( child: AnimatedOpacity(
opacity: numericValue == selectedValue ? 1 : 0, opacity: numericValue == selectedValue ? 1 : 0,

View File

@@ -9,44 +9,42 @@ class ThemeModeButton extends StatelessWidget {
final bool? disabled; final bool? disabled;
const ThemeModeButton({ const ThemeModeButton({
Key? key, super.key,
required this.icon, required this.icon,
required this.value, required this.value,
required this.selected, required this.selected,
required this.label, required this.label,
required this.onChanged, required this.onChanged,
this.disabled this.disabled,
}) : super(key: key); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final Color greyBackgroundColor = Theme.of(context).brightness == Brightness.light final Color greyBackgroundColor = Theme.of(context).brightness == Brightness.light
?const Color.fromRGBO(200, 200, 200, 1) ? const Color.fromRGBO(200, 200, 200, 1)
:const Color.fromRGBO(50, 50, 50, 1); : const Color.fromRGBO(50, 50, 50, 1);
final Color greyIconColor = Theme.of(context).brightness == Brightness.light final Color greyIconColor = Theme.of(context).brightness == Brightness.light
? const Color.fromRGBO(130, 130, 130, 1) ? const Color.fromRGBO(130, 130, 130, 1)
: const Color.fromRGBO(100, 100, 100, 1); : const Color.fromRGBO(100, 100, 100, 1);
return ElevatedButton( return ElevatedButton(
onPressed: disabled == null || disabled == false onPressed: disabled == null || disabled == false ? () => onChanged(value) : null,
? () => onChanged(value)
: null,
style: ButtonStyle( style: ButtonStyle(
elevation: MaterialStateProperty.all(0), elevation: WidgetStateProperty.all(0),
shape: MaterialStateProperty.all( shape: WidgetStateProperty.all(
RoundedRectangleBorder( RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30), borderRadius: BorderRadius.circular(30),
)
), ),
backgroundColor: MaterialStateProperty.all( ),
backgroundColor: WidgetStateProperty.all(
value == selected value == selected
? disabled == null || disabled == false ? disabled == null || disabled == false
? Theme.of(context).colorScheme.primary ? Theme.of(context).colorScheme.primary
: greyBackgroundColor : greyBackgroundColor
: disabled == null || disabled == false : disabled == null || disabled == false
? Theme.of(context).colorScheme.surfaceVariant ? Theme.of(context).colorScheme.surfaceContainerHighest
: greyBackgroundColor, : greyBackgroundColor,
) ),
), ),
child: AnimatedContainer( child: AnimatedContainer(
width: 118, width: 118,
@@ -60,7 +58,9 @@ class ThemeModeButton extends StatelessWidget {
icon, icon,
color: value == selected color: value == selected
? disabled == null || disabled == false ? disabled == null || disabled == false
? Theme.of(context).colorScheme.primary.computeLuminance() > 0.5 ? Colors.black : Colors.white ? Theme.of(context).colorScheme.primary.computeLuminance() > 0.5
? Colors.black
: Colors.white
: greyIconColor : greyIconColor
: disabled == null || disabled == false : disabled == null || disabled == false
? Theme.of(context).colorScheme.primary ? Theme.of(context).colorScheme.primary
@@ -72,14 +72,16 @@ class ThemeModeButton extends StatelessWidget {
style: TextStyle( style: TextStyle(
color: value == selected color: value == selected
? disabled == null || disabled == false ? disabled == null || disabled == false
? Theme.of(context).colorScheme.primary.computeLuminance() > 0.5 ? Colors.black : Colors.white ? Theme.of(context).colorScheme.primary.computeLuminance() > 0.5
? Colors.black
: Colors.white
: greyIconColor : greyIconColor
: disabled == null || disabled == false : disabled == null || disabled == false
? Theme.of(context).colorScheme.primary ? Theme.of(context).colorScheme.primary
: greyIconColor, : greyIconColor,
fontSize: 18 fontSize: 18,
),
), ),
)
], ],
), ),
), ),

View File

@@ -5,7 +5,7 @@ import 'package:linkdy/i18n/strings.g.dart';
import 'package:linkdy/providers/api_client.provider.dart'; import 'package:linkdy/providers/api_client.provider.dart';
class DisconnectModal extends ConsumerWidget { class DisconnectModal extends ConsumerWidget {
const DisconnectModal({Key? key}) : super(key: key); const DisconnectModal({super.key});
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {

View File

@@ -101,8 +101,8 @@ class GeneralSettings extends ConsumerWidget {
t.settings.generalSettings.disconnectFromServer, t.settings.generalSettings.disconnectFromServer,
), ),
style: const ButtonStyle( style: const ButtonStyle(
foregroundColor: MaterialStatePropertyAll(Colors.white), foregroundColor: WidgetStatePropertyAll(Colors.white),
backgroundColor: MaterialStatePropertyAll(Colors.red), backgroundColor: WidgetStatePropertyAll(Colors.red),
), ),
), ),
], ],

View File

@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:linkdy/i18n/strings.g.dart'; import 'package:linkdy/i18n/strings.g.dart';
class AddTagErrorModal extends StatelessWidget { class AddTagErrorModal extends StatelessWidget {
const AddTagErrorModal({Key? key}) : super(key: key); const AddTagErrorModal({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@@ -14,7 +14,7 @@ class CustomListTile extends StatelessWidget {
final Color? color; final Color? color;
const CustomListTile({ const CustomListTile({
Key? key, super.key,
required this.title, required this.title,
this.subtitle, this.subtitle,
this.subtitleWidget, this.subtitleWidget,
@@ -26,7 +26,7 @@ class CustomListTile extends StatelessWidget {
this.disabled, this.disabled,
this.onHover, this.onHover,
this.color, this.color,
}) : super(key: key); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -80,16 +80,17 @@ class CustomListTile extends StatelessWidget {
? Theme.of(context).colorScheme.onSurfaceVariant.withOpacity(0.38) ? Theme.of(context).colorScheme.onSurfaceVariant.withOpacity(0.38)
: Theme.of(context).colorScheme.onSurfaceVariant, : Theme.of(context).colorScheme.onSurfaceVariant,
fontSize: 14, fontSize: 14,
fontWeight: FontWeight.w400), fontWeight: FontWeight.w400,
),
), ),
]
], ],
),
)
], ],
), ),
), ),
if (trailing != null) ...[const SizedBox(width: 16), trailing!] ],
),
),
if (trailing != null) ...[const SizedBox(width: 16), trailing!],
], ],
), ),
), ),

View File

@@ -62,16 +62,17 @@ class CustomSettingsTile extends StatelessWidget {
style: TextStyle( style: TextStyle(
color: Theme.of(context).listTileTheme.textColor, color: Theme.of(context).listTileTheme.textColor,
fontSize: 14, fontSize: 14,
fontWeight: FontWeight.w400), fontWeight: FontWeight.w400,
),
), ),
]
], ],
),
)
], ],
), ),
), ),
if (trailing != null) ...[const SizedBox(width: 10), trailing!] ],
),
),
if (trailing != null) ...[const SizedBox(width: 10), trailing!],
], ],
); );
@@ -88,8 +89,10 @@ class CustomSettingsTile extends StatelessWidget {
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(28), borderRadius: BorderRadius.circular(28),
color: thisItem == selectedItem ? Theme.of(context).colorScheme.primaryContainer : null), color: thisItem == selectedItem ? Theme.of(context).colorScheme.primaryContainer : null,
child: tileBody), ),
child: tileBody,
),
), ),
), ),
); );

View File

@@ -25,12 +25,14 @@ class CustomSwitchListTile extends StatelessWidget {
return Material( return Material(
color: Colors.transparent, color: Colors.transparent,
child: InkWell( child: InkWell(
onTap: disabled != null && disabled == true onTap: disabled != null && disabled == true ? null : () => onChanged(!value),
? null
: () => onChanged(!value),
child: Padding( child: Padding(
padding: padding ?? const EdgeInsets.only( padding: padding ??
top: 12, left: 16, right: 18, bottom: 16 const EdgeInsets.only(
top: 12,
left: 16,
right: 18,
bottom: 16,
), ),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
@@ -55,31 +57,29 @@ class CustomSwitchListTile extends StatelessWidget {
: Theme.of(context).colorScheme.onSurface, : Theme.of(context).colorScheme.onSurface,
), ),
), ),
if (subtitle != null) ... [ if (subtitle != null) ...[
const SizedBox(height: 5), const SizedBox(height: 5),
SizedBox( SizedBox(
width: MediaQuery.of(context).size.width-110, width: MediaQuery.of(context).size.width - 110,
child: Text( child: Text(
subtitle!, subtitle!,
style: TextStyle( style: TextStyle(
fontSize: 14, fontSize: 14,
color: disabled != null && disabled == true color: disabled != null && disabled == true
? Theme.of(context).listTileTheme.textColor!.withOpacity(0.38) ? Theme.of(context).listTileTheme.textColor!.withOpacity(0.38)
: Theme.of(context).listTileTheme.textColor : Theme.of(context).listTileTheme.textColor,
), ),
), ),
), ),
] ],
], ],
), ),
), ),
const SizedBox(width: 16), const SizedBox(width: 16),
Switch( Switch(
value: value, value: value,
onChanged: disabled != null && disabled == true onChanged: disabled != null && disabled == true ? null : onChanged,
? null ),
: onChanged,
)
], ],
), ),
), ),

View File

@@ -4,9 +4,9 @@ class EnterSearchTermScreen extends StatelessWidget {
final String message; final String message;
const EnterSearchTermScreen({ const EnterSearchTermScreen({
Key? key, super.key,
required this.message, required this.message,
}) : super(key: key); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@@ -4,9 +4,9 @@ class ErrorScreen extends StatelessWidget {
final String error; final String error;
const ErrorScreen({ const ErrorScreen({
Key? key, super.key,
required this.error, required this.error,
}) : super(key: key); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@@ -4,9 +4,9 @@ class NoDataScreen extends StatelessWidget {
final String message; final String message;
const NoDataScreen({ const NoDataScreen({
Key? key, super.key,
required this.message, required this.message,
}) : super(key: key); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@@ -5,9 +5,9 @@ class PageTransition extends StatelessWidget {
final Widget child; final Widget child;
const PageTransition({ const PageTransition({
Key? key, super.key,
required this.child, required this.child,
}) : super(key: key); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@@ -4,9 +4,9 @@ class ProcessDialog extends StatelessWidget {
final String message; final String message;
const ProcessDialog({ const ProcessDialog({
Key? key, super.key,
required this.message, required this.message,
}) : super(key: key); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -29,7 +29,7 @@ class ProcessDialog extends StatelessWidget {
message, message,
style: TextStyle(color: Theme.of(context).colorScheme.onSurface), style: TextStyle(color: Theme.of(context).colorScheme.onSurface),
), ),
) ),
], ],
), ),
), ),

View File

@@ -5,10 +5,10 @@ class SectionLabel extends StatelessWidget {
final EdgeInsets? padding; final EdgeInsets? padding;
const SectionLabel({ const SectionLabel({
Key? key, super.key,
required this.label, required this.label,
this.padding, this.padding,
}) : super(key: key); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
class SliverTabBody extends StatelessWidget { class SliverTabBody extends StatelessWidget {
final Widget child; final Widget child;
const SliverTabBody({Key? key, required this.child}) : super(key: key); const SliverTabBody({super.key, required this.child});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -28,10 +28,10 @@ class SliverTabBodyRefresh extends StatelessWidget {
final Future<void> Function() onRefresh; final Future<void> Function() onRefresh;
const SliverTabBodyRefresh({ const SliverTabBodyRefresh({
Key? key, super.key,
required this.child, required this.child,
required this.onRefresh, required this.onRefresh,
}) : super(key: key); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {