Compare commits

..

No commits in common. "202ab20747bdaf8dee441a80616a475ca3f32e36" and "e1c9bc4d809c4f702c5db4655267473d438928da" have entirely different histories.

11 changed files with 379 additions and 348 deletions

View File

@ -1,69 +0,0 @@
import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/material.dart';
class GlobalTheme {
static final Color _lightFocusColor = Colors.black.withOpacity(0.12);
static final Color _darkFocusColor = Colors.white.withOpacity(0.12);
static ThemeData lightThemeData(ColorScheme? dynamicColorScheme) {
return themeData(lightColorScheme, dynamicColorScheme, _lightFocusColor);
}
static ThemeData darkThemeData(ColorScheme? dynamicColorScheme) {
return themeData(darkColorScheme, dynamicColorScheme, _darkFocusColor);
}
static ThemeData themeData(ColorScheme colorScheme, ColorScheme? dynamic,
Color focusColor) {
return ThemeData(
colorScheme: colorScheme,
canvasColor: colorScheme.surface,
scaffoldBackgroundColor: colorScheme.surface,
highlightColor: Colors.transparent,
dividerColor: colorScheme.outline,
focusColor: focusColor,
useMaterial3: true,
appBarTheme: AppBarTheme(
backgroundColor: colorScheme.surface,
foregroundColor: colorScheme.onSurface,
elevation: 0
)
);
}
static ColorScheme get lightColorScheme {
return ColorScheme(
primary: Color(0xff747ab5),
onPrimary: Colors.white,
secondary: Color(0x335d63a6),// Color(0xFFDDE0E0),
onSecondary: Color(0xFF322942),
tertiary: Colors.grey[300],
onTertiary: Colors.grey[700],
surfaceContainer: (Colors.grey[100])!,
outline: (Colors.grey[400])!,
error: (Colors.red[400])!,
onError: Colors.white,
surface: Color(0xFFFAFBFB),
onSurface: Color(0xFF241E30),
brightness: Brightness.light,
);
}
static ColorScheme get darkColorScheme {
return ColorScheme(
primary: Color(0xff5d63a6),
secondary: Colors.blue.shade500,
secondaryContainer: Color(0xff1c1c1c),
surface: Colors.black,
surfaceContainer: Color(0xff0f0f0f),
onSurfaceVariant: Colors.grey[400],
tertiary: Colors.grey[900],
onTertiary: Colors.grey,
outline: (Colors.grey[800])!,
error: (Colors.red[400])!,
onError: Colors.white,
onPrimary: Colors.white,
onSecondary: (Colors.grey[400])!,
onSurface: Colors.white,
brightness: Brightness.dark,
);
}
}

View File

@ -1,5 +1,4 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:shlink_app/global_theme.dart';
import 'package:shlink_app/views/login_view.dart'; import 'package:shlink_app/views/login_view.dart';
import 'package:shlink_app/views/navigationbar_view.dart'; import 'package:shlink_app/views/navigationbar_view.dart';
import 'globals.dart' as globals; import 'globals.dart' as globals;
@ -27,9 +26,7 @@ class MyApp extends StatelessWidget {
return MaterialApp( return MaterialApp(
title: 'Shlink', title: 'Shlink',
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
theme: GlobalTheme.lightThemeData(lightColorScheme), theme: ThemeData(
darkTheme: GlobalTheme.darkThemeData(darkColorScheme),
/*theme: ThemeData(
appBarTheme: const AppBarTheme( appBarTheme: const AppBarTheme(
backgroundColor: Color(0xfffafafa), backgroundColor: Color(0xfffafafa),
), ),
@ -44,7 +41,7 @@ class MyApp extends StatelessWidget {
colorScheme: darkColorScheme?.copyWith(surface: Colors.black) ?? colorScheme: darkColorScheme?.copyWith(surface: Colors.black) ??
_defaultDarkColorScheme, _defaultDarkColorScheme,
useMaterial3: true, useMaterial3: true,
),*/ ),
home: const InitialPage()); home: const InitialPage());
}); });
} }

View File

@ -1,22 +0,0 @@
import 'package:flutter/material.dart';
import 'package:shlink_app/API/server_manager.dart';
SnackBar buildApiErrorSnackbar(Failure r, BuildContext context) {
var text = "";
if (r is RequestFailure) {
text = r.description;
} else {
text = (r as ApiFailure).detail;
if ((r).invalidElements != null) {
text = "$text: ${(r).invalidElements}";
}
}
final snackBar = SnackBar(
content: Text(text, style: TextStyle(color: Theme.of(context).colorScheme.onError)),
backgroundColor: Theme.of(context).colorScheme.error,
behavior: SnackBarBehavior.floating);
return snackBar;
}

View File

@ -5,7 +5,7 @@ import 'package:flutter_sharing_intent/flutter_sharing_intent.dart';
import 'package:flutter_sharing_intent/model/sharing_file.dart'; import 'package:flutter_sharing_intent/model/sharing_file.dart';
import 'package:qr_flutter/qr_flutter.dart'; import 'package:qr_flutter/qr_flutter.dart';
import 'package:shlink_app/API/Classes/ShlinkStats/shlink_stats.dart'; import 'package:shlink_app/API/Classes/ShlinkStats/shlink_stats.dart';
import 'package:shlink_app/util/build_api_error_snackbar.dart'; import 'package:shlink_app/API/server_manager.dart';
import 'package:shlink_app/views/short_url_edit_view.dart'; import 'package:shlink_app/views/short_url_edit_view.dart';
import 'package:shlink_app/views/url_list_view.dart'; import 'package:shlink_app/views/url_list_view.dart';
import 'package:shlink_app/widgets/available_servers_bottom_sheet.dart'; import 'package:shlink_app/widgets/available_servers_bottom_sheet.dart';
@ -68,9 +68,18 @@ class _HomeViewState extends State<HomeView> {
shlinkStats = l; shlinkStats = l;
}); });
}, (r) { }, (r) {
ScaffoldMessenger.of(context).showSnackBar( var text = "";
buildApiErrorSnackbar(r, context) if (r is RequestFailure) {
); text = r.description;
} else {
text = (r as ApiFailure).detail;
}
final snackBar = SnackBar(
content: Text(text),
backgroundColor: Colors.red[400],
behavior: SnackBarBehavior.floating);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}); });
} }
@ -82,9 +91,18 @@ class _HomeViewState extends State<HomeView> {
shortUrlsLoaded = true; shortUrlsLoaded = true;
}); });
}, (r) { }, (r) {
ScaffoldMessenger.of(context).showSnackBar( var text = "";
buildApiErrorSnackbar(r, context) if (r is RequestFailure) {
); text = r.description;
} else {
text = (r as ApiFailure).detail;
}
final snackBar = SnackBar(
content: Text(text),
backgroundColor: Colors.red[400],
behavior: SnackBarBehavior.floating);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}); });
} }
@ -121,7 +139,7 @@ class _HomeViewState extends State<HomeView> {
}, },
child: Text(globals.serverManager.getServerUrl(), child: Text(globals.serverManager.getServerUrl(),
style: TextStyle( style: TextStyle(
fontSize: 16, color: Theme.of(context).colorScheme.onTertiary)), fontSize: 16, color: Colors.grey[600])),
) )
], ],
)), )),
@ -171,7 +189,7 @@ class _HomeViewState extends State<HomeView> {
'Create one by tapping the "+" button below', 'Create one by tapping the "+" button below',
style: TextStyle( style: TextStyle(
fontSize: 16, fontSize: 16,
color: Theme.of(context).colorScheme.onSecondary), color: Colors.grey[600]),
), ),
) )
], ],
@ -233,12 +251,18 @@ class _HomeViewState extends State<HomeView> {
eyeStyle: QrEyeStyle( eyeStyle: QrEyeStyle(
eyeShape: QrEyeShape.square, eyeShape: QrEyeShape.square,
color: color:
Theme.of(context).colorScheme.onPrimary MediaQuery.of(context).platformBrightness ==
Brightness.dark
? Colors.white
: Colors.black,
), ),
dataModuleStyle: QrDataModuleStyle( dataModuleStyle: QrDataModuleStyle(
dataModuleShape: QrDataModuleShape.square, dataModuleShape: QrDataModuleShape.square,
color: color:
Theme.of(context).colorScheme.onPrimary MediaQuery.of(context).platformBrightness ==
Brightness.dark
? Colors.white
: Colors.black,
), ),
))), ))),
), ),

View File

@ -135,7 +135,7 @@ class _LoginViewState extends State<LoginView> {
children: [ children: [
Flexible( Flexible(
child: Text(_errorMessage, child: Text(_errorMessage,
style: TextStyle(color: Theme.of(context).colorScheme.onError), style: const TextStyle(color: Colors.red),
textAlign: TextAlign.center)) textAlign: TextAlign.center))
], ],
), ),

View File

@ -40,7 +40,9 @@ class _OpenSourceLicensesViewState extends State<OpenSourceLicensesView> {
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
color: Theme.of(context).colorScheme.surfaceContainer, color: Theme.of(context).brightness == Brightness.light
? Colors.grey[100]
: Colors.grey[900],
), ),
child: Padding( child: Padding(
padding: const EdgeInsets.only( padding: const EdgeInsets.only(
@ -52,13 +54,13 @@ class _OpenSourceLicensesViewState extends State<OpenSourceLicensesView> {
style: const TextStyle( style: const TextStyle(
fontWeight: FontWeight.bold, fontSize: 18)), fontWeight: FontWeight.bold, fontSize: 18)),
Text("Version: ${currentLicense.version ?? "N/A"}", Text("Version: ${currentLicense.version ?? "N/A"}",
style: TextStyle(color: Theme.of(context).colorScheme.onTertiary)), style: const TextStyle(color: Colors.grey)),
const SizedBox(height: 8), const SizedBox(height: 8),
Divider(color: Theme.of(context).dividerColor), const Divider(),
const SizedBox(height: 8), const SizedBox(height: 8),
Text(currentLicense.license, Text(currentLicense.license,
textAlign: TextAlign.justify, textAlign: TextAlign.justify,
style: TextStyle(color: Theme.of(context).colorScheme.onTertiary)), style: const TextStyle(color: Colors.grey)),
], ],
), ),
), ),
@ -67,12 +69,12 @@ class _OpenSourceLicensesViewState extends State<OpenSourceLicensesView> {
); );
}, childCount: LicenseUtil.getLicenses().length), }, childCount: LicenseUtil.getLicenses().length),
), ),
SliverToBoxAdapter( const SliverToBoxAdapter(
child: Padding( child: Padding(
padding: EdgeInsets.only(top: 8, bottom: 20), padding: EdgeInsets.only(top: 8, bottom: 20),
child: Text( child: Text(
"Thank you to all maintainers of these repositories 💝", "Thank you to all maintainers of these repositories 💝",
style: TextStyle(color: Theme.of(context).colorScheme.onTertiary), style: TextStyle(color: Colors.grey),
textAlign: TextAlign.center, textAlign: TextAlign.center,
), ),
)) ))

View File

@ -3,7 +3,7 @@ import 'package:shlink_app/API/Classes/ShortURL/RedirectRule/condition_device_ty
import 'package:shlink_app/API/Classes/ShortURL/RedirectRule/redirect_rule_condition.dart'; import 'package:shlink_app/API/Classes/ShortURL/RedirectRule/redirect_rule_condition.dart';
import 'package:shlink_app/API/Classes/ShortURL/RedirectRule/redirect_rule_condition_type.dart'; import 'package:shlink_app/API/Classes/ShortURL/RedirectRule/redirect_rule_condition_type.dart';
import 'package:shlink_app/API/Classes/ShortURL/short_url.dart'; import 'package:shlink_app/API/Classes/ShortURL/short_url.dart';
import 'package:shlink_app/util/build_api_error_snackbar.dart'; import 'package:shlink_app/API/server_manager.dart';
import '../globals.dart' as globals; import '../globals.dart' as globals;
import '../API/Classes/ShortURL/RedirectRule/redirect_rule.dart'; import '../API/Classes/ShortURL/RedirectRule/redirect_rule.dart';
@ -41,9 +41,18 @@ class _RedirectRulesDetailViewState extends State<RedirectRulesDetailView> {
_sortListByPriority(); _sortListByPriority();
return true; return true;
}, (r) { }, (r) {
ScaffoldMessenger.of(context).showSnackBar( var text = "";
buildApiErrorSnackbar(r, context) if (r is RequestFailure) {
); text = r.description;
} else {
text = (r as ApiFailure).detail;
}
final snackBar = SnackBar(
content: Text(text),
backgroundColor: Colors.red[400],
behavior: SnackBarBehavior.floating);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
return false; return false;
}); });
} }
@ -54,9 +63,18 @@ class _RedirectRulesDetailViewState extends State<RedirectRulesDetailView> {
response.fold((l) { response.fold((l) {
Navigator.pop(context); Navigator.pop(context);
}, (r) { }, (r) {
ScaffoldMessenger.of(context).showSnackBar( var text = "";
buildApiErrorSnackbar(r, context) if (r is RequestFailure) {
); text = r.description;
} else {
text = (r as ApiFailure).detail;
}
final snackBar = SnackBar(
content: Text(text),
backgroundColor: Colors.red[400],
behavior: SnackBarBehavior.floating);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
return false; return false;
}); });
} }
@ -123,7 +141,7 @@ class _RedirectRulesDetailViewState extends State<RedirectRulesDetailView> {
child: Text( child: Text(
'Adding redirect rules will be supported soon!', 'Adding redirect rules will be supported soon!',
style: TextStyle( style: TextStyle(
fontSize: 16, color: Theme.of(context).colorScheme.onSecondary), fontSize: 16, color: Colors.grey[600]),
), ),
) )
], ],
@ -203,7 +221,10 @@ class _ListCellState extends State<_ListCell> {
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border( border: Border(
bottom: BorderSide( bottom: BorderSide(
color: Theme.of(context).dividerColor)), color: MediaQuery.of(context).platformBrightness ==
Brightness.dark
? Colors.grey[800]!
: Colors.grey[300]!)),
), ),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@ -231,7 +252,10 @@ class _ListCellState extends State<_ListCell> {
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(4), borderRadius: BorderRadius.circular(4),
color: color:
Theme.of(context).colorScheme.tertiary, MediaQuery.of(context).platformBrightness ==
Brightness.dark
? Colors.grey[900]
: Colors.grey[300],
), ),
child: Text(_conditionToTagString(condition)), child: Text(_conditionToTagString(condition)),
), ),
@ -245,13 +269,19 @@ class _ListCellState extends State<_ListCell> {
children: [ children: [
IconButton( IconButton(
disabledColor: disabledColor:
Theme.of(context).disabledColor, MediaQuery.of(context).platformBrightness ==
Brightness.dark
? Colors.grey[700]
: Colors.grey[400],
onPressed: widget.moveUp, onPressed: widget.moveUp,
icon: const Icon(Icons.arrow_upward), icon: const Icon(Icons.arrow_upward),
), ),
IconButton( IconButton(
disabledColor: disabledColor:
Theme.of(context).disabledColor, MediaQuery.of(context).platformBrightness ==
Brightness.dark
? Colors.grey[700]
: Colors.grey[400],
onPressed: widget.moveDown, onPressed: widget.moveDown,
icon: const Icon(Icons.arrow_downward), icon: const Icon(Icons.arrow_downward),
), ),

View File

@ -1,6 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:package_info_plus/package_info_plus.dart'; import 'package:package_info_plus/package_info_plus.dart';
import 'package:shlink_app/util/build_api_error_snackbar.dart'; import 'package:shlink_app/API/server_manager.dart';
import 'package:shlink_app/views/opensource_licenses_view.dart'; import 'package:shlink_app/views/opensource_licenses_view.dart';
import 'package:shlink_app/widgets/available_servers_bottom_sheet.dart'; import 'package:shlink_app/widgets/available_servers_bottom_sheet.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
@ -43,9 +43,19 @@ class _SettingsViewState extends State<SettingsView> {
setState(() { setState(() {
_serverStatus = ServerStatus.disconnected; _serverStatus = ServerStatus.disconnected;
}); });
ScaffoldMessenger.of(context).showSnackBar(
buildApiErrorSnackbar(r, context) var text = "";
); if (r is RequestFailure) {
text = r.description;
} else {
text = (r as ApiFailure).detail;
}
final snackBar = SnackBar(
content: Text(text),
backgroundColor: Colors.red[400],
behavior: SnackBarBehavior.floating);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}); });
} }
@ -77,7 +87,9 @@ class _SettingsViewState extends State<SettingsView> {
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
color: Theme.of(context).colorScheme.surfaceContainer color: Theme.of(context).brightness == Brightness.light
? Colors.grey[100]
: Colors.grey[900],
), ),
child: Padding( child: Padding(
padding: const EdgeInsets.all(12.0), padding: const EdgeInsets.all(12.0),
@ -98,29 +110,29 @@ class _SettingsViewState extends State<SettingsView> {
Column( Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text("Connected to", const Text("Connected to",
style: TextStyle(color: Theme.of(context).colorScheme.onTertiary)), style: TextStyle(color: Colors.grey)),
Text(globals.serverManager.getServerUrl(), Text(globals.serverManager.getServerUrl(),
style: const TextStyle( style: const TextStyle(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 16)), fontSize: 16)),
Row( Row(
children: [ children: [
Text("API Version: ", const Text("API Version: ",
style: TextStyle( style: TextStyle(
color: Theme.of(context).colorScheme.onTertiary, color: Colors.grey,
fontWeight: FontWeight.w600)), fontWeight: FontWeight.w600)),
Text(globals.serverManager.getApiVersion(), Text(globals.serverManager.getApiVersion(),
style: TextStyle( style: const TextStyle(
color: Theme.of(context).colorScheme.onTertiary)), color: Colors.grey)),
const SizedBox(width: 16), const SizedBox(width: 16),
Text("Server Version: ", const Text("Server Version: ",
style: TextStyle( style: TextStyle(
color: Theme.of(context).colorScheme.onTertiary, color: Colors.grey,
fontWeight: FontWeight.w600)), fontWeight: FontWeight.w600)),
Text(_serverVersion, Text(_serverVersion,
style: style:
TextStyle(color: Theme.of(context).colorScheme.onTertiary)) const TextStyle(color: Colors.grey))
], ],
), ),
], ],
@ -131,7 +143,7 @@ class _SettingsViewState extends State<SettingsView> {
), ),
), ),
const SizedBox(height: 8), const SizedBox(height: 8),
Divider(color: Theme.of(context).dividerColor), const Divider(),
const SizedBox(height: 8), const SizedBox(height: 8),
GestureDetector( GestureDetector(
onTap: () { onTap: () {
@ -142,7 +154,9 @@ class _SettingsViewState extends State<SettingsView> {
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
color: Theme.of(context).colorScheme.surfaceContainer color: Theme.of(context).brightness == Brightness.light
? Colors.grey[100]
: Colors.grey[900],
), ),
child: const Padding( child: const Padding(
padding: EdgeInsets.only( padding: EdgeInsets.only(
@ -176,7 +190,9 @@ class _SettingsViewState extends State<SettingsView> {
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
color: Theme.of(context).colorScheme.surfaceContainer color: Theme.of(context).brightness == Brightness.light
? Colors.grey[100]
: Colors.grey[900],
), ),
child: const Padding( child: const Padding(
padding: EdgeInsets.only( padding: EdgeInsets.only(
@ -210,7 +226,9 @@ class _SettingsViewState extends State<SettingsView> {
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
color: Theme.of(context).colorScheme.surfaceContainer color: Theme.of(context).brightness == Brightness.light
? Colors.grey[100]
: Colors.grey[900],
), ),
child: const Padding( child: const Padding(
padding: EdgeInsets.only( padding: EdgeInsets.only(
@ -243,11 +261,13 @@ class _SettingsViewState extends State<SettingsView> {
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
color: color:
Theme.of(context).colorScheme.surfaceContainer Theme.of(context).brightness == Brightness.light
? Colors.grey[100]
: Colors.grey[900],
), ),
child: Text( child: Text(
"${packageInfo.appName}, v${packageInfo.version} (${packageInfo.buildNumber})", "${packageInfo.appName}, v${packageInfo.version} (${packageInfo.buildNumber})",
style: TextStyle(color: Theme.of(context).colorScheme.onSecondary), style: const TextStyle(color: Colors.grey),
), ),
) )
], ],

View File

@ -4,7 +4,6 @@ import 'package:flutter/services.dart';
import 'package:shlink_app/API/Classes/ShortURL/short_url.dart'; import 'package:shlink_app/API/Classes/ShortURL/short_url.dart';
import 'package:shlink_app/API/Classes/ShortURLSubmission/short_url_submission.dart'; import 'package:shlink_app/API/Classes/ShortURLSubmission/short_url_submission.dart';
import 'package:shlink_app/API/server_manager.dart'; import 'package:shlink_app/API/server_manager.dart';
import 'package:shlink_app/util/build_api_error_snackbar.dart';
import '../globals.dart' as globals; import '../globals.dart' as globals;
class ShortURLEditView extends StatefulWidget { class ShortURLEditView extends StatefulWidget {
@ -73,34 +72,6 @@ class _ShortURLEditViewState extends State<ShortURLEditView>
} }
} }
void _saveButtonPressed() {
if (!isSaving) {
setState(() {
isSaving = true;
longUrlError = "";
randomSlugLengthError = "";
});
if (longUrlController.text == "") {
setState(() {
longUrlError = "URL cannot be empty";
isSaving = false;
});
return;
} else if (int.tryParse(randomSlugLengthController.text) ==
null ||
int.tryParse(randomSlugLengthController.text)! < 1 ||
int.tryParse(randomSlugLengthController.text)! > 50) {
setState(() {
randomSlugLengthError = "invalid number";
isSaving = false;
});
return;
} else {
_submitShortUrl();
}
}
}
void _submitShortUrl() async { void _submitShortUrl() async {
var newSubmission = ShortURLSubmission( var newSubmission = ShortURLSubmission(
longUrl: longUrlController.text, longUrl: longUrlController.text,
@ -148,9 +119,22 @@ class _ShortURLEditViewState extends State<ShortURLEditView>
isSaving = false; isSaving = false;
}); });
ScaffoldMessenger.of(context).showSnackBar( var text = "";
buildApiErrorSnackbar(r, context)
); if (r is RequestFailure) {
text = r.description;
} else {
text = (r as ApiFailure).detail;
if ((r).invalidElements != null) {
text = "$text: ${(r).invalidElements}";
}
}
final snackBar = SnackBar(
content: Text(text),
backgroundColor: Colors.red[400],
behavior: SnackBarBehavior.floating);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
return false; return false;
}); });
} }
@ -166,9 +150,8 @@ class _ShortURLEditViewState extends State<ShortURLEditView>
), ),
SliverToBoxAdapter( SliverToBoxAdapter(
child: Padding( child: Padding(
padding: EdgeInsets.only(top: 16, left: 8, right: 8), padding: const EdgeInsets.only(left: 16, right: 16, top: 16),
child: Wrap( child: Column(
runSpacing: 16,
children: [ children: [
TextField( TextField(
controller: longUrlController, controller: longUrlController,
@ -183,6 +166,7 @@ class _ShortURLEditViewState extends State<ShortURLEditView>
], ],
)), )),
), ),
const SizedBox(height: 16),
Row( Row(
children: [ children: [
Expanded( Expanded(
@ -191,8 +175,11 @@ class _ShortURLEditViewState extends State<ShortURLEditView>
controller: customSlugController, controller: customSlugController,
style: TextStyle( style: TextStyle(
color: randomSlug color: randomSlug
? Theme.of(context).colorScheme.onTertiary ? Colors.grey
: Theme.of(context).colorScheme.onPrimary), : Theme.of(context).brightness ==
Brightness.light
? Colors.black
: Colors.white),
onChanged: (_) { onChanged: (_) {
if (randomSlug) { if (randomSlug) {
setState(() { setState(() {
@ -244,6 +231,7 @@ class _ShortURLEditViewState extends State<ShortURLEditView>
) )
], ],
), ),
if (randomSlug) const SizedBox(height: 16),
if (randomSlug) if (randomSlug)
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
@ -268,6 +256,7 @@ class _ShortURLEditViewState extends State<ShortURLEditView>
)) ))
], ],
), ),
const SizedBox(height: 16),
TextField( TextField(
controller: titleController, controller: titleController,
decoration: const InputDecoration( decoration: const InputDecoration(
@ -280,6 +269,7 @@ class _ShortURLEditViewState extends State<ShortURLEditView>
], ],
)), )),
), ),
const SizedBox(height: 16),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
@ -294,6 +284,7 @@ class _ShortURLEditViewState extends State<ShortURLEditView>
) )
], ],
), ),
const SizedBox(height: 16),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
@ -308,6 +299,7 @@ class _ShortURLEditViewState extends State<ShortURLEditView>
) )
], ],
), ),
const SizedBox(height: 16),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
@ -324,13 +316,36 @@ class _ShortURLEditViewState extends State<ShortURLEditView>
), ),
], ],
), ),
) ))
)
], ],
), ),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
onPressed: () { onPressed: () {
_saveButtonPressed(); if (!isSaving) {
setState(() {
isSaving = true;
longUrlError = "";
randomSlugLengthError = "";
});
if (longUrlController.text == "") {
setState(() {
longUrlError = "URL cannot be empty";
isSaving = false;
});
return;
} else if (int.tryParse(randomSlugLengthController.text) ==
null ||
int.tryParse(randomSlugLengthController.text)! < 1 ||
int.tryParse(randomSlugLengthController.text)! > 50) {
setState(() {
randomSlugLengthError = "invalid number";
isSaving = false;
});
return;
} else {
_submitShortUrl();
}
}
}, },
child: isSaving child: isSaving
? const Padding( ? const Padding(

View File

@ -1,7 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:shlink_app/API/Classes/ShortURL/short_url.dart'; import 'package:shlink_app/API/Classes/ShortURL/short_url.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:shlink_app/util/build_api_error_snackbar.dart'; import 'package:shlink_app/API/server_manager.dart';
import 'package:shlink_app/views/redirect_rules_detail_view.dart'; import 'package:shlink_app/views/redirect_rules_detail_view.dart';
import 'package:shlink_app/views/short_url_edit_view.dart'; import 'package:shlink_app/views/short_url_edit_view.dart';
import 'package:shlink_app/widgets/url_tags_list_widget.dart'; import 'package:shlink_app/widgets/url_tags_list_widget.dart';
@ -67,9 +67,18 @@ class _URLDetailViewState extends State<URLDetailView> {
ScaffoldMessenger.of(context).showSnackBar(snackBar); ScaffoldMessenger.of(context).showSnackBar(snackBar);
return true; return true;
}, (r) { }, (r) {
ScaffoldMessenger.of(context).showSnackBar( var text = "";
buildApiErrorSnackbar(r, context) if (r is RequestFailure) {
); text = r.description;
} else {
text = (r as ApiFailure).detail;
}
final snackBar = SnackBar(
content: Text(text),
backgroundColor: Colors.red[400],
behavior: SnackBarBehavior.floating);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
return false; return false;
}); });
}, },
@ -198,7 +207,10 @@ class _ListCellState extends State<_ListCell> {
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border( border: Border(
top: BorderSide( top: BorderSide(
color: Theme.of(context).dividerColor)), color: MediaQuery.of(context).platformBrightness ==
Brightness.dark
? Colors.grey[800]!
: Colors.grey[300]!)),
), ),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
@ -214,7 +226,10 @@ class _ListCellState extends State<_ListCell> {
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
color: Theme.of(context).colorScheme.outline, color: Theme.of(context).brightness ==
Brightness.dark
? Colors.grey[700]
: Colors.grey[300],
), ),
), ),
), ),

View File

@ -1,7 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:qr_flutter/qr_flutter.dart'; import 'package:qr_flutter/qr_flutter.dart';
import 'package:shlink_app/API/Classes/ShortURL/short_url.dart'; import 'package:shlink_app/API/Classes/ShortURL/short_url.dart';
import 'package:shlink_app/util/build_api_error_snackbar.dart'; import 'package:shlink_app/API/server_manager.dart';
import 'package:shlink_app/views/short_url_edit_view.dart'; import 'package:shlink_app/views/short_url_edit_view.dart';
import 'package:shlink_app/views/url_detail_view.dart'; import 'package:shlink_app/views/url_detail_view.dart';
import 'package:shlink_app/widgets/url_tags_list_widget.dart'; import 'package:shlink_app/widgets/url_tags_list_widget.dart';
@ -38,9 +38,18 @@ class _URLListViewState extends State<URLListView> {
}); });
return true; return true;
}, (r) { }, (r) {
ScaffoldMessenger.of(context).showSnackBar( var text = "";
buildApiErrorSnackbar(r, context) if (r is RequestFailure) {
); text = r.description;
} else {
text = (r as ApiFailure).detail;
}
final snackBar = SnackBar(
content: Text(text),
backgroundColor: Colors.red[400],
behavior: SnackBarBehavior.floating);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
return false; return false;
}); });
} }
@ -90,7 +99,7 @@ class _URLListViewState extends State<URLListView> {
'Create one by tapping the "+" button below', 'Create one by tapping the "+" button below',
style: TextStyle( style: TextStyle(
fontSize: 16, fontSize: 16,
color: Theme.of(context).colorScheme.onSecondary), color: Colors.grey[600]),
), ),
) )
], ],
@ -142,11 +151,18 @@ class _URLListViewState extends State<URLListView> {
eyeStyle: QrEyeStyle( eyeStyle: QrEyeStyle(
eyeShape: QrEyeShape.square, eyeShape: QrEyeShape.square,
color: color:
Theme.of(context).colorScheme.onPrimary, MediaQuery.of(context).platformBrightness ==
Brightness.dark
? Colors.white
: Colors.black,
), ),
dataModuleStyle: QrDataModuleStyle( dataModuleStyle: QrDataModuleStyle(
dataModuleShape: QrDataModuleShape.square, dataModuleShape: QrDataModuleShape.square,
color: Theme.of(context).colorScheme.onPrimary, color:
MediaQuery.of(context).platformBrightness ==
Brightness.dark
? Colors.white
: Colors.black,
), ),
))), ))),
), ),
@ -193,7 +209,10 @@ class _ShortURLCellState extends State<ShortURLCell> {
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border( border: Border(
bottom: BorderSide( bottom: BorderSide(
color: Theme.of(context).dividerColor)), color: MediaQuery.of(context).platformBrightness ==
Brightness.dark
? Colors.grey[800]!
: Colors.grey[300]!)),
), ),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
@ -212,7 +231,7 @@ class _ShortURLCellState extends State<ShortURLCell> {
maxLines: 1, maxLines: 1,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
textScaleFactor: 0.9, textScaleFactor: 0.9,
style: TextStyle(color: Theme.of(context).colorScheme.onTertiary), style: TextStyle(color: Colors.grey[600]),
), ),
// List tags in a row // List tags in a row
UrlTagsListWidget(tags: widget.shortURL.tags) UrlTagsListWidget(tags: widget.shortURL.tags)