85 lines
2.5 KiB
Dart
85 lines
2.5 KiB
Dart
import 'package:fitnessapp/Views/add_exercise.dart';
|
|
import 'package:fitnessapp/Views/exercise_details_view.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'dart:async';
|
|
import 'dart:convert';
|
|
|
|
class ExerciseView extends StatefulWidget{
|
|
String title;
|
|
String id;
|
|
|
|
ExerciseView(this.title, this.id);
|
|
|
|
@override
|
|
State<StatefulWidget> createState() {
|
|
// TODO: implement createState
|
|
return ExerciseViewState();
|
|
}
|
|
}
|
|
|
|
class ExerciseViewState extends State<ExerciseView>{
|
|
|
|
List data;
|
|
|
|
Future<List> getWorkouts() async {
|
|
var response = await http.get(
|
|
"http://10.16.17.18/api/workout.php?token=satbwertwhbertnwertwertghwertgwertg&workout="+this.widget.id,
|
|
headers: {
|
|
"Accept": "application/json"
|
|
}
|
|
);
|
|
|
|
this.setState(() {
|
|
data = JsonDecoder().convert(response.body);
|
|
});
|
|
return data;
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
getWorkouts();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// TODO: implement build
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
leading: IconButton(
|
|
onPressed: (){
|
|
Navigator.pop(context);
|
|
},
|
|
icon: Icon(Icons.arrow_back),
|
|
),
|
|
title: Text(this.widget.title),
|
|
),
|
|
body: RefreshIndicator(
|
|
child: ListView.builder(
|
|
itemCount: data == null ? 0 : data.length,
|
|
itemBuilder: (BuildContext context, int index){
|
|
return new ListTile(
|
|
leading: Icon(data[index]['type'] == 'duration' ? Icons.access_alarm : (data[index]['type'] == 'count' ? Icons.filter_1 : Icons.transfer_within_a_station)),
|
|
title: Text((index+1).toString() + ': ' + data[index]['name']),
|
|
subtitle: Text(data[index]['sets'] + ' x ' + data[index]['amount'] + ' ' + data[index]['unit']),
|
|
onTap: (){
|
|
Navigator.push(context, MaterialPageRoute(
|
|
builder: (context) => ExerciseDetailsView(data[index]['name'], data[index]['description'], data[index]['amount'], data[index]['type'], data[index]['unit'])
|
|
));
|
|
},
|
|
);
|
|
},
|
|
),
|
|
onRefresh: getWorkouts,
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: (){
|
|
Navigator.push(context, MaterialPageRoute(
|
|
builder: (context) => AddExercise(int.parse(this.widget.id))
|
|
));
|
|
},
|
|
child: Icon(Icons.add),
|
|
),
|
|
);
|
|
}
|
|
} |