Skip to content

Sorting functionality added #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
*.swp
.DS_Store
.atom/
.build/
.buildlog/
.history
.svn/
.swiftpm/
migrate_working_dir/

# IntelliJ related
Expand Down
1 change: 1 addition & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,5 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 303789365c3a8d7bc562e5e65d7e8e15218ec5c6


COCOAPODS: 1.15.0
2 changes: 1 addition & 1 deletion ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import UIKit
import Flutter
import Photos

@UIApplicationMain
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
Expand Down
25 changes: 25 additions & 0 deletions lib/core/models/sort_option.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
enum SortOption {
nameAsc,
nameDesc,
dateModifiedNewest,
dateModifiedOldest,
dateCreatedNewest,
dateCreatedOldest;

String get label {
switch (this) {
case SortOption.nameAsc:
return 'Name (A to Z)';
case SortOption.nameDesc:
return 'Name (Z to A)';
case SortOption.dateModifiedNewest:
return 'Last Modified (Newest)';
case SortOption.dateModifiedOldest:
return 'Last Modified (Oldest)';
case SortOption.dateCreatedNewest:
return 'Date Created (Newest)';
case SortOption.dateCreatedOldest:
return 'Date Created (Oldest)';
}
}
}
82 changes: 82 additions & 0 deletions lib/ui/pages/landing_page/components/search_text_field.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import 'package:flutter/material.dart';
import 'package:paintroid/core/models/sort_option.dart';
import 'package:paintroid/ui/theme/theme.dart';

class SearchTextField extends StatelessWidget {
final TextEditingController controller;
final FocusNode focusNode;
final ValueChanged<String> onChanged;
final SortOption currentSortOption;
final ValueChanged<SortOption> onSortOptionSelected;

const SearchTextField({
super.key,
required this.controller,
required this.focusNode,
required this.onChanged,
required this.currentSortOption,
required this.onSortOptionSelected,
});

@override
Widget build(BuildContext context) {

return Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
TextField(
controller: controller,
focusNode: focusNode,
autofocus: true,
style:
TextStyle(color: PaintroidTheme.of(context).onSurfaceColor),
decoration: InputDecoration(
hintText: 'Search projects...',
hintStyle: TextStyle(
color: PaintroidTheme.of(context)
.onSurfaceColor
.withOpacity(0.6),
),
border: InputBorder.none,
),
onChanged: onChanged,
),
],
),
),
PopupMenuButton<SortOption>(
icon: Icon(
Icons.sort,
color: PaintroidTheme.of(context).onSurfaceColor,
),
tooltip: 'Sort options',
onSelected: onSortOptionSelected,
itemBuilder: (context) => SortOption.values
.map(
(option) => PopupMenuItem<SortOption>(
value: option,
child: Row(
children: [
Icon(
option == currentSortOption
? Icons.radio_button_checked
: Icons.radio_button_unchecked,
size: 18,
),
const SizedBox(width: 8),
Text(option.label),
],
),
),
)
.toList(),
),
const SizedBox(width: 2),
],
);
}
}
28 changes: 28 additions & 0 deletions lib/ui/pages/landing_page/components/search_toggle_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:flutter/material.dart';

class SearchToggleButton extends StatelessWidget {
final bool isSearchActive;
final VoidCallback onSearchStart;
final VoidCallback onSearchEnd;

const SearchToggleButton({
super.key,
required this.isSearchActive,
required this.onSearchStart,
required this.onSearchEnd,
});

@override
Widget build(BuildContext context) {
if (isSearchActive) {
return IconButton(
icon: const Icon(Icons.close),
onPressed: onSearchEnd,
);
}
return IconButton(
icon: const Icon(Icons.search),
onPressed: onSearchStart,
);
}
}
Loading