-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to search for exercises in records tab (#300)
* Implemented ExerciseSearchDelegate class to allow searching data * Updated records tab to allow searching for records based on exercise name * Bump v0.8.3+39
- Loading branch information
Showing
3 changed files
with
163 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class ExerciseSearchDelegate extends SearchDelegate { | ||
final List<Map<String, dynamic>> records; | ||
final bool isKg; | ||
final Function(double) convertWeight; | ||
|
||
ExerciseSearchDelegate({ | ||
required this.records, | ||
required this.isKg, | ||
required this.convertWeight, | ||
}); | ||
|
||
@override | ||
List<Widget> buildActions(BuildContext context) { | ||
return [ | ||
IconButton( | ||
icon: Icon(Icons.clear), | ||
onPressed: () { | ||
query = ''; | ||
}, | ||
), | ||
]; | ||
} | ||
|
||
@override | ||
Widget buildLeading(BuildContext context) { | ||
return IconButton( | ||
icon: Icon(Icons.arrow_back), | ||
onPressed: () { | ||
close(context, null); | ||
}, | ||
); | ||
} | ||
|
||
@override | ||
Widget buildResults(BuildContext context) { | ||
final filteredRecords = records.where((record) { | ||
final exercise = record['exercise'] as String; | ||
return exercise.toLowerCase().contains(query.toLowerCase()); | ||
}).toList(); | ||
|
||
return _buildRecordList(filteredRecords); | ||
} | ||
|
||
@override | ||
Widget buildSuggestions(BuildContext context) { | ||
final filteredRecords = records.where((record) { | ||
final exercise = record['exercise'] as String; | ||
return exercise.toLowerCase().contains(query.toLowerCase()); | ||
}).toList(); | ||
|
||
return _buildRecordList(filteredRecords); | ||
} | ||
|
||
Widget _buildRecordList(List<Map<String, dynamic>> records) { | ||
return ListView.builder( | ||
itemCount: records.length, | ||
itemBuilder: (context, index) { | ||
final record = records[index]; | ||
final exercise = record['exercise'] as String; | ||
final weight = record['weight']; | ||
final reps = record['reps']; | ||
final displayWeight = | ||
convertWeight(weight is String ? double.parse(weight) : weight); | ||
|
||
return ListTile( | ||
title: Text(exercise), | ||
subtitle: Text('${displayWeight.toStringAsFixed(1)} x $reps reps'), | ||
); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters