harmonyV

Note Example

Apr 24th, 2026
71
0
Never
5
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 4.61 KB | None | 0 0
  1. class NoteTile extends StatelessWidget {
  2.   final Note note;
  3.  
  4.   const NoteTile({
  5.     super.key,
  6.     required this.note,
  7.   });
  8.  
  9.   @override
  10.   Widget build(BuildContext context) {
  11.     final textTheme = Theme.of(context).textTheme;
  12.     final colorScheme = Theme.of(context).colorScheme;
  13.  
  14.     return PostHogMaskWidget(
  15.       child: MyCard(
  16.         onTap: () => showNoteCard(context, note),
  17.         padding: .all(12),
  18.         child: Column(
  19.           crossAxisAlignment: .start,
  20.           children: [
  21.             Row(
  22.               mainAxisAlignment: MainAxisAlignment.spaceBetween,
  23.               spacing: 12,
  24.               children: [
  25.                 Flexible(
  26.                   child: Text(
  27.                     note.title,
  28.                     maxLines: 2,
  29.                     overflow: TextOverflow.ellipsis,
  30.                     style: textTheme.titleMedium?.copyWith(
  31.                       color: colorScheme.onSurfaceVariant,
  32.                     ),
  33.                   ),
  34.                 ),
  35.                 if (note.recipeId != null)
  36.                   Icon(
  37.                     LucideIcons.link2,
  38.                     color: colorScheme.primary,
  39.                   ),
  40.               ],
  41.             ),
  42.             const Padding(
  43.               padding: EdgeInsets.symmetric(vertical: 4),
  44.               child: Divider(),
  45.             ),
  46.             Tag(
  47.               label: Text(note.bodyReaction.title),
  48.               highlightColor: note.bodyReaction.color,
  49.               isSelected: true,
  50.             ),
  51.             const SizedBox(height: 4),
  52.             Text(
  53.               note.detailedReaction,
  54.               maxLines: 2,
  55.               overflow: TextOverflow.ellipsis,
  56.               style: Theme.of(context).textTheme.bodyMedium,
  57.             ),
  58.             const SizedBox(height: 8),
  59.             Align(
  60.               alignment: Alignment.bottomRight,
  61.               child: Text(
  62.                 DateFormat('d MMM').format(note.createdAt),
  63.                 style: Theme.of(context).textTheme.bodySmall,
  64.               ),
  65.             ),
  66.           ],
  67.         ),
  68.       ),
  69.     );
  70.   }
  71. }
  72.  
  73. void showNoteCard(
  74.   BuildContext context,
  75.   Note note, {
  76.   bool? showActions,
  77.   bool showBackLink = true,
  78. }) {
  79.   log('Showing note card for noteId: $noteId');
  80.   PosthogService.captureNoteInteraction('note_opened');
  81.  
  82.   showModalBottomSheet<void>(
  83.     useRootNavigator: true,
  84.     context: context,
  85.     backgroundColor: Theme.of(context).colorScheme.surfaceContainerHigh,
  86.     builder: (context) => SingleChildScrollView(
  87.       padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
  88.       child: NoteCard(
  89.         noteId: note,
  90.         showActions: showActions,
  91.         showBackLink: showBackLink,
  92.       ),
  93.     ),
  94.   );
  95. }
  96.  
  97. class NoteCard extends ConsumerWidget {
  98.   final Note note;
  99.   final bool showBackLink;
  100.   final bool showActions;
  101.  
  102.   const NoteCard({
  103.     super.key,
  104.     required this.note,
  105.     this.showBackLink = true,
  106.     bool? showActions,
  107.   }): showActions = testNote == null ? (showActions ?? true) : false;
  108.  
  109.  
  110.   @override
  111.   Widget build(BuildContext context, WidgetRef ref) {
  112.     final textTheme = Theme.of(context).textTheme;
  113.  
  114.     return Column(
  115.             crossAxisAlignment: CrossAxisAlignment.start,
  116.             spacing: 8,
  117.             children: [
  118.               _Heading(
  119.                 note: note,
  120.                 showActions: showActions,
  121.                 showBackLink: showBackLink,
  122.               ),
  123.               _ReactionSection(note: note),
  124.               if (note.opinion != null)
  125.                 InfoCard(
  126.                   title: 'Taste and Enjoyment',
  127.                   child: Text(note.opinion!, style: textTheme.bodyMedium),
  128.                 ),
  129.               if (note.observations != null)
  130.                 InfoCard(
  131.                   title: 'Potential Triggers or Aids',
  132.                   child: Text(note.observations!, style: textTheme.bodyMedium),
  133.                 ),
  134.               if (note.improvements != null)
  135.                 InfoCard(
  136.                   title: 'Improvements or Changes',
  137.                   child: Text(note.improvements!, style: textTheme.bodyMedium),
  138.                 ),
  139.               Align(
  140.                 alignment: Alignment.centerRight,
  141.                 child: MyCard(
  142.                   padding: .all(8),
  143.                   child: Text(
  144.                     DateFormat('dd MMM yyyy').format(note.createdAt),
  145.                     style: Theme.of(
  146.                       context,
  147.                     ).textTheme.bodySmall?.copyWith(fontStyle: .italic),
  148.                   ),
  149.                 ),
  150.               ),
  151.             ],
  152.           )
  153.   }
  154. }
  155.  
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment