Skip to content
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

Added Search bar at Outreachy screen #396

Merged
merged 1 commit into from
Oct 30, 2024
Merged
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
125 changes: 85 additions & 40 deletions lib/programs screen/outreachy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class _OutreachyScreenState extends State<OutreachyScreen> {
}
}

void filterProjects() {
void filterProjects([String query = ""]) {
projectList = _getProjectsByYear();

if (!selectedSkills.contains('All')) {
Expand All @@ -100,6 +100,13 @@ class _OutreachyScreenState extends State<OutreachyScreen> {
.toList();
}

if (query.isNotEmpty) {
projectList = projectList
.where((project) =>
project.name.toLowerCase().contains(query.toLowerCase()))
.toList();
}

setState(() {});
}

Expand Down Expand Up @@ -139,45 +146,45 @@ class _OutreachyScreenState extends State<OutreachyScreen> {
onRefresh: _refresh,
child: Scaffold(
appBar: AppBar(
leading: IconButton(
icon: const Icon(Icons.arrow_back_ios),

onPressed: () => Navigator.of(context).pop(),
),
centerTitle: true,
title: const Text('Outreachy'), actions: <Widget>[
IconButton(
icon: (isBookmarked)
? const Icon(Icons.bookmark_add_rounded)
: const Icon(Icons.bookmark_add_outlined),
onPressed: () {
setState(() {
isBookmarked = !isBookmarked;
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
isBookmarked ? 'Bookmark added' : 'Bookmark removed'),
duration: const Duration(seconds: 2),
),
);
if (isBookmarked) {
HandleBookmark.addBookmark(currentProject, currentPage);
} else {
HandleBookmark.deleteBookmark(currentProject);
}
},
),
IconButton(
icon: Icon(Icons.info_outline),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => OUTREACHYInfo()),
);
},
),
]),
leading: IconButton(
icon: const Icon(Icons.arrow_back_ios),
onPressed: () => Navigator.of(context).pop(),
),
centerTitle: true,
title: const Text('Outreachy'),
actions: <Widget>[
IconButton(
icon: (isBookmarked)
? const Icon(Icons.bookmark_add_rounded)
: const Icon(Icons.bookmark_add_outlined),
onPressed: () {
setState(() {
isBookmarked = !isBookmarked;
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
isBookmarked ? 'Bookmark added' : 'Bookmark removed'),
duration: const Duration(seconds: 2),
),
);
if (isBookmarked) {
HandleBookmark.addBookmark(currentProject, currentPage);
} else {
HandleBookmark.deleteBookmark(currentProject);
}
},
),
IconButton(
icon: Icon(Icons.info_outline),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => OUTREACHYInfo()),
);
},
),
]),
body: FutureBuilder<void>(
future: getProjectFunction,
builder: (context, snapshot) {
Expand All @@ -191,6 +198,8 @@ class _OutreachyScreenState extends State<OutreachyScreen> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_buildSearchBar(),
const SizedBox(height: 20),
_buildYearButtons(),
const SizedBox(height: 20),
_buildMultiSelectField(
Expand Down Expand Up @@ -221,6 +230,42 @@ class _OutreachyScreenState extends State<OutreachyScreen> {
);
}

Widget _buildSearchBar() {
return TextFormField(
decoration: InputDecoration(
filled: true,
hintText: 'Search',
suffixIcon: const Icon(Icons.search),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(color: Color(0xFFEEEEEE)),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(color: Color(0xFFEEEEEE)),
),
disabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(color: Color(0xFFEEEEEE)),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(color: Color(0xFFEEEEEE)),
),
contentPadding:
const EdgeInsets.symmetric(vertical: 12.0, horizontal: 20.0),
),
onFieldSubmitted: (value) {
filterProjects(value);
},
onChanged: (value) {
if (value.isEmpty) {
filterProjects(value);
}
},
);
}

Widget _buildYearButtons() {
return SizedBox(
height: MediaQuery.of(context).size.height * 0.2,
Expand Down
Loading