From f64b1360d9a40f770b1956874d9ca93db841a5ae Mon Sep 17 00:00:00 2001 From: Kima Date: Sun, 5 May 2024 21:53:39 +0200 Subject: [PATCH] images are now removable --- .../lib/pages/notes/notes_page.dart | 45 +++--- .../pages/notes/submenu/note_view_screen.dart | 129 ++++++++++-------- .../notes/submenu/notes_screen.i18n.dart | 3 + 3 files changed, 101 insertions(+), 76 deletions(-) diff --git a/refilc_mobile_ui/lib/pages/notes/notes_page.dart b/refilc_mobile_ui/lib/pages/notes/notes_page.dart index 47c509f..f777747 100644 --- a/refilc_mobile_ui/lib/pages/notes/notes_page.dart +++ b/refilc_mobile_ui/lib/pages/notes/notes_page.dart @@ -149,26 +149,31 @@ class NotesPageState extends State with TickerProviderStateMixin { CupertinoPageRoute( builder: (context) => NoteViewScreen(note: e))), ) - : Container( - height: MediaQuery.of(context).size.width / 2.42, - width: MediaQuery.of(context).size.width / 2.42, - decoration: BoxDecoration( - boxShadow: [ - if (Provider.of(context, listen: false) - .shadowEffect) - BoxShadow( - offset: const Offset(0, 21), - blurRadius: 23.0, - color: Theme.of(context).shadowColor, - ), - ], - ), - child: ClipRRect( - borderRadius: BorderRadius.circular(16.0), - child: Image.memory( - const Base64Decoder().convert(e.content), - fit: BoxFit.cover, - gaplessPlayback: true, + : GestureDetector( + onTap: () => Navigator.of(context, rootNavigator: true).push( + CupertinoPageRoute( + builder: (context) => NoteViewScreen(note: e))), + child: Container( + height: MediaQuery.of(context).size.width / 2.42, + width: MediaQuery.of(context).size.width / 2.42, + decoration: BoxDecoration( + boxShadow: [ + if (Provider.of(context, listen: false) + .shadowEffect) + BoxShadow( + offset: const Offset(0, 21), + blurRadius: 23.0, + color: Theme.of(context).shadowColor, + ), + ], + ), + child: ClipRRect( + borderRadius: BorderRadius.circular(16.0), + child: Image.memory( + const Base64Decoder().convert(e.content), + fit: BoxFit.cover, + gaplessPlayback: true, + ), ), ), ), diff --git a/refilc_mobile_ui/lib/pages/notes/submenu/note_view_screen.dart b/refilc_mobile_ui/lib/pages/notes/submenu/note_view_screen.dart index 5ea5ddd..6c53209 100644 --- a/refilc_mobile_ui/lib/pages/notes/submenu/note_view_screen.dart +++ b/refilc_mobile_ui/lib/pages/notes/submenu/note_view_screen.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:flutter_markdown/flutter_markdown.dart'; import 'package:refilc/api/providers/self_note_provider.dart'; import 'package:refilc/models/self_note.dart'; @@ -8,6 +10,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_feather_icons/flutter_feather_icons.dart'; import 'package:provider/provider.dart'; import 'package:markdown/markdown.dart' as md; +import 'notes_screen.i18n.dart'; class NoteViewScreen extends StatefulWidget { const NoteViewScreen({super.key, required this.note}); @@ -30,7 +33,9 @@ class NoteViewScreenState extends State { surfaceTintColor: Theme.of(context).scaffoldBackgroundColor, leading: BackButton(color: AppColors.of(context).text), title: Text( - widget.note.title ?? '${widget.note.content.split(' ')[0]}...', + widget.note.noteType == NoteType.text + ? (widget.note.title ?? '${widget.note.content.split(' ')[0]}...') + : 'image_note'.i18n, style: TextStyle( color: AppColors.of(context).text, fontSize: 26.0, @@ -38,52 +43,55 @@ class NoteViewScreenState extends State { ), ), actions: [ - ClipRRect( - borderRadius: BorderRadius.circular(10.1), - child: GestureDetector( - onTap: () { - // handle tap - Navigator.of(context, rootNavigator: true).push( - CupertinoPageRoute( - builder: (context) => - AddNoteScreen(initialNote: widget.note))); - }, - child: Container( - color: Theme.of(context).colorScheme.secondary.withOpacity(0.2), - child: Padding( - padding: const EdgeInsets.all(8.0), - child: Stack( - children: [ - IconTheme( - data: IconThemeData( - color: Theme.of(context).colorScheme.secondary, + if (widget.note.noteType == NoteType.text) + ClipRRect( + borderRadius: BorderRadius.circular(10.1), + child: GestureDetector( + onTap: () { + // handle tap + Navigator.of(context, rootNavigator: true).push( + CupertinoPageRoute( + builder: (context) => + AddNoteScreen(initialNote: widget.note))); + }, + child: Container( + color: + Theme.of(context).colorScheme.secondary.withOpacity(0.2), + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Stack( + children: [ + IconTheme( + data: IconThemeData( + color: Theme.of(context).colorScheme.secondary, + ), + child: const Icon( + FeatherIcons.edit, + size: 20.0, + ), ), - child: const Icon( - FeatherIcons.edit, - size: 20.0, + IconTheme( + data: IconThemeData( + color: + Theme.of(context).brightness == Brightness.light + ? Colors.black.withOpacity(.5) + : Colors.white.withOpacity(.3), + ), + child: const Icon( + FeatherIcons.edit, + size: 20.0, + ), ), - ), - IconTheme( - data: IconThemeData( - color: - Theme.of(context).brightness == Brightness.light - ? Colors.black.withOpacity(.5) - : Colors.white.withOpacity(.3), - ), - child: const Icon( - FeatherIcons.edit, - size: 20.0, - ), - ), - ], + ], + ), ), ), ), ), - ), - const SizedBox( - width: 10, - ), + if (widget.note.noteType == NoteType.text) + const SizedBox( + width: 10, + ), ClipRRect( borderRadius: BorderRadius.circular(10.1), child: GestureDetector( @@ -140,21 +148,30 @@ class NoteViewScreenState extends State { child: Column( children: [ Expanded( - child: MarkdownBody( - data: widget.note.content, - extensionSet: md.ExtensionSet( - md.ExtensionSet.gitHubFlavored.blockSyntaxes, - [ - md.EmojiSyntax(), - ...md.ExtensionSet.gitHubFlavored.inlineSyntaxes - ], - ), - styleSheet: MarkdownStyleSheet( - p: const TextStyle( - fontSize: 15.0, - ), - ), - ), + child: widget.note.noteType == NoteType.text + ? MarkdownBody( + data: widget.note.content, + extensionSet: md.ExtensionSet( + md.ExtensionSet.gitHubFlavored.blockSyntaxes, + [ + md.EmojiSyntax(), + ...md.ExtensionSet.gitHubFlavored.inlineSyntaxes + ], + ), + styleSheet: MarkdownStyleSheet( + p: const TextStyle( + fontSize: 15.0, + ), + ), + ) + : ClipRRect( + borderRadius: BorderRadius.circular(10.0), + child: Image.memory( + const Base64Decoder().convert(widget.note.content), + fit: BoxFit.contain, + gaplessPlayback: true, + ), + ), ), // Expanded( // child: Text( diff --git a/refilc_mobile_ui/lib/pages/notes/submenu/notes_screen.i18n.dart b/refilc_mobile_ui/lib/pages/notes/submenu/notes_screen.i18n.dart index bbe6033..77d6128 100644 --- a/refilc_mobile_ui/lib/pages/notes/submenu/notes_screen.i18n.dart +++ b/refilc_mobile_ui/lib/pages/notes/submenu/notes_screen.i18n.dart @@ -18,6 +18,7 @@ extension SettingsLocalization on String { "click_here": "Click here", "select_image": "to select an image", "new_image": "New Image", + "image_note": "Image", }, "hu_hu": { "notes": "Füzet", @@ -34,6 +35,7 @@ extension SettingsLocalization on String { "click_here": "Kattints ide", "select_image": "kép kiválasztásához", "new_image": "Új kép", + "image_note": "Kép", }, "de_de": { "notes": "Broschüre", @@ -50,6 +52,7 @@ extension SettingsLocalization on String { "click_here": "Klicken Sie hier", "select_image": "um ein Bild auszuwählen", "new_image": "Neues Bild", + "image_note": "Bild", }, };