-
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.
Merge pull request #42 from andreped:records-tab
Added records tab showing max weight lifted per exercise
- Loading branch information
Showing
3 changed files
with
70 additions
and
1 deletion.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import 'package:flutter/material.dart'; | ||
import '../core/database.dart'; | ||
|
||
class RecordsTab extends StatefulWidget { | ||
@override | ||
_RecordsTabState createState() => _RecordsTabState(); | ||
} | ||
|
||
class _RecordsTabState extends State<RecordsTab> { | ||
final DatabaseHelper _dbHelper = DatabaseHelper(); | ||
|
||
Future<Map<String, Map<String, dynamic>>> _getMaxWeights() async { | ||
return await _dbHelper.getMaxWeightsForExercises(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Padding( | ||
padding: const EdgeInsets.all(16.0), | ||
child: FutureBuilder<Map<String, Map<String, dynamic>>>( | ||
future: _getMaxWeights(), | ||
builder: (context, snapshot) { | ||
if (snapshot.connectionState == ConnectionState.waiting) { | ||
return const Center(child: CircularProgressIndicator()); | ||
} else if (snapshot.hasError) { | ||
return Center(child: Text('Error: ${snapshot.error}')); | ||
} else if (!snapshot.hasData || snapshot.data!.isEmpty) { | ||
return const Center(child: Text('No records available')); | ||
} | ||
|
||
final maxWeights = snapshot.data!; | ||
return ListView.builder( | ||
itemCount: maxWeights.length, | ||
itemBuilder: (context, index) { | ||
final exercise = maxWeights.keys.elementAt(index); | ||
final weightData = maxWeights[exercise]!; | ||
final weight = weightData['maxWeight']; | ||
final reps = weightData['reps']; | ||
return ListTile( | ||
title: Text(exercise), | ||
trailing: Text('${weight!.toStringAsFixed(2)} kg x $reps reps'), | ||
); | ||
}, | ||
); | ||
}, | ||
), | ||
); | ||
} | ||
} |