|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:phosphor_flutter/phosphor_flutter.dart'; |
| 3 | +import 'package:stacked/stacked.dart'; |
| 4 | + |
| 5 | +import '../../../common/colors.dart'; |
| 6 | +import '../../../common/themes.dart'; |
| 7 | +import '../../common/ui_helpers.dart'; |
| 8 | +import 'bookmarks_viewmodel.dart'; |
| 9 | + |
| 10 | +class BookmarksView extends StackedView<BookmarksViewModel> { |
| 11 | + const BookmarksView({super.key}); |
| 12 | + |
| 13 | + @override |
| 14 | + Widget builder( |
| 15 | + BuildContext context, |
| 16 | + BookmarksViewModel viewModel, |
| 17 | + Widget? child, |
| 18 | + ) { |
| 19 | + bool isPortrait = isPortraitOrientation(context); |
| 20 | + return PopScope( |
| 21 | + canPop: false, |
| 22 | + onPopInvoked: viewModel.onPopInvoked, |
| 23 | + child: Scaffold( |
| 24 | + backgroundColor: context.theme.appColors.background, |
| 25 | + appBar: AppBar( |
| 26 | + backgroundColor: context.theme.appColors.background, |
| 27 | + centerTitle: true, |
| 28 | + scrolledUnderElevation: 0.0, |
| 29 | + title: isPortrait |
| 30 | + ? null |
| 31 | + : Text( |
| 32 | + 'Your Bookmarks', |
| 33 | + style: TextStyle( |
| 34 | + color: context.theme.appColors.primary, |
| 35 | + fontSize: 18.0, |
| 36 | + fontWeight: FontWeight.w500, |
| 37 | + ), |
| 38 | + ), |
| 39 | + ), |
| 40 | + body: Container( |
| 41 | + padding: EdgeInsets.only(top: isPortrait ? 26.0 : 0.0), |
| 42 | + child: Column( |
| 43 | + mainAxisSize: MainAxisSize.min, |
| 44 | + children: [ |
| 45 | + if (isPortrait) |
| 46 | + Padding( |
| 47 | + padding: const EdgeInsets.only(bottom: 36.0), |
| 48 | + child: Text( |
| 49 | + 'Your Bookmarks', |
| 50 | + style: TextStyle( |
| 51 | + color: context.theme.appColors.primary, |
| 52 | + fontSize: 26.0, |
| 53 | + fontWeight: FontWeight.bold, |
| 54 | + ), |
| 55 | + ), |
| 56 | + ), |
| 57 | + viewModel.bookmarks.isEmpty |
| 58 | + ? Row( |
| 59 | + mainAxisAlignment: MainAxisAlignment.center, |
| 60 | + children: [ |
| 61 | + Padding( |
| 62 | + padding: const EdgeInsets.symmetric(vertical: 40.0, horizontal: 25.0), |
| 63 | + child: Text( |
| 64 | + 'No bookmarks yet.', |
| 65 | + style: TextStyle( |
| 66 | + color: context.theme.appColors.primary, |
| 67 | + fontSize: 15.0, |
| 68 | + ), |
| 69 | + ), |
| 70 | + ), |
| 71 | + ], |
| 72 | + ) |
| 73 | + : Expanded( |
| 74 | + child: ListView.builder( |
| 75 | + itemCount: viewModel.bookmarks.length, |
| 76 | + itemBuilder: (BuildContext context, int index) { |
| 77 | + return InkWell( |
| 78 | + onTap: () => {}, |
| 79 | + child: Padding( |
| 80 | + padding: const EdgeInsets.symmetric(vertical: 14.0, horizontal: 25.0), |
| 81 | + child: Row( |
| 82 | + mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 83 | + crossAxisAlignment: CrossAxisAlignment.center, |
| 84 | + children: [ |
| 85 | + Row( |
| 86 | + crossAxisAlignment: CrossAxisAlignment.center, |
| 87 | + children: [ |
| 88 | + PhosphorIcon( |
| 89 | + PhosphorIcons.bookmarkSimple(PhosphorIconsStyle.bold), |
| 90 | + color: viewModel.bookmarks[index].textToColor(), |
| 91 | + size: 20.0, |
| 92 | + ), |
| 93 | + const SizedBox(width: 12.0), |
| 94 | + Text( |
| 95 | + viewModel.bookmarks[index], |
| 96 | + style: TextStyle( |
| 97 | + color: context.theme.appColors.primary, |
| 98 | + fontSize: 16.0, |
| 99 | + fontWeight: FontWeight.w500, |
| 100 | + ), |
| 101 | + ), |
| 102 | + ], |
| 103 | + ), |
| 104 | + PhosphorIcon( |
| 105 | + PhosphorIcons.caretRight(PhosphorIconsStyle.bold), |
| 106 | + color: context.theme.appColors.primary, |
| 107 | + size: 18.0, |
| 108 | + semanticLabel: 'Caret right', |
| 109 | + ), |
| 110 | + ], |
| 111 | + ), |
| 112 | + ), |
| 113 | + ); |
| 114 | + }, |
| 115 | + ), |
| 116 | + ), |
| 117 | + ], |
| 118 | + ), |
| 119 | + ), |
| 120 | + ), |
| 121 | + ); |
| 122 | + } |
| 123 | + |
| 124 | + @override |
| 125 | + BookmarksViewModel viewModelBuilder( |
| 126 | + BuildContext context, |
| 127 | + ) => |
| 128 | + BookmarksViewModel(); |
| 129 | +} |
0 commit comments