From 65fd2f09069284f986bfc9fff7f1868709c8f18f Mon Sep 17 00:00:00 2001 From: Branislav Nohaj Date: Sat, 4 Oct 2025 16:12:18 +0200 Subject: [PATCH] Add separate license info widget for CC BY-SA notice --- .../add_exercise/license_info_widget.dart | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 lib/widgets/add_exercise/license_info_widget.dart diff --git a/lib/widgets/add_exercise/license_info_widget.dart b/lib/widgets/add_exercise/license_info_widget.dart new file mode 100644 index 00000000..146a2e4c --- /dev/null +++ b/lib/widgets/add_exercise/license_info_widget.dart @@ -0,0 +1,77 @@ +import 'package:flutter/material.dart'; +import 'package:url_launcher/url_launcher.dart'; +import 'package:wger/l10n/generated/app_localizations.dart'; + +/// Static widget displaying CC BY-SA 4.0 license notice for image uploads +/// +/// This widget informs users that by uploading images, they agree to release +/// them under the CC BY-SA 4.0 license. The license name is clickable and +/// opens the Creative Commons license page. +/// +/// Being a separate widget allows Flutter to optimize rendering since +/// this content never changes. +class LicenseInfoWidget extends StatelessWidget { + const LicenseInfoWidget({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + final colorScheme = Theme.of(context).colorScheme; + + return Container( + padding: const EdgeInsets.all(12), + decoration: BoxDecoration( + color: colorScheme.surfaceVariant, + borderRadius: BorderRadius.circular(4), + border: Border.all(color: colorScheme.outline), + ), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Icon( + Icons.info_outline, + size: 20, + color: colorScheme.onSurfaceVariant, + ), + const SizedBox(width: 8), + Expanded( + child: RichText( + text: TextSpan( + style: TextStyle( + fontSize: 12, + color: colorScheme.onSurfaceVariant, + ), + children: [ + TextSpan( + text: AppLocalizations.of(context).imageDetailsLicenseNoticePrefix, + ), + WidgetSpan( + child: GestureDetector( + onTap: () async { + final url = Uri.parse('https://creativecommons.org/licenses/by-sa/4.0/'); + if (await canLaunchUrl(url)) { + await launchUrl(url, mode: LaunchMode.externalApplication); + } + }, + child: Text( + 'CC BY-SA 4.0', + style: TextStyle( + fontSize: 12, + color: colorScheme.primary, + fontWeight: FontWeight.bold, + decoration: TextDecoration.underline, + ), + ), + ), + ), + TextSpan( + text: AppLocalizations.of(context).imageDetailsLicenseNoticeSuffix, + ), + ], + ), + ), + ), + ], + ), + ); + } +} \ No newline at end of file