75 lines
1.9 KiB
Dart
75 lines
1.9 KiB
Dart
import 'package:fitnessapp/Views/exercises_view.dart';
|
|
import 'package:fitnessapp/Views/new_workout_view.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'dart:async';
|
|
import 'dart:convert';
|
|
|
|
class WorkoutsView extends StatefulWidget{
|
|
String token;
|
|
|
|
|
|
WorkoutsView(this.token);
|
|
|
|
@override
|
|
State<StatefulWidget> createState() {
|
|
// TODO: implement createState
|
|
return WorkoutsViewState();
|
|
}
|
|
}
|
|
|
|
class WorkoutsViewState extends State<WorkoutsView>{
|
|
List data;
|
|
|
|
Future<List> getWorkouts() async {
|
|
var response = await http.get(
|
|
"http://10.16.17.18/api/index.php?token=" + super.widget.token,
|
|
headers: {
|
|
"Accept": "application/json"
|
|
}
|
|
);
|
|
|
|
this.setState(() {
|
|
data = JsonDecoder().convert(response.body);
|
|
});
|
|
return data;
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
this.getWorkouts();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// TODO: implement build
|
|
return Scaffold(
|
|
body: RefreshIndicator(
|
|
child: ListView.builder(
|
|
itemCount: data == null ? 0 : data.length,
|
|
itemBuilder: (BuildContext context, int index){
|
|
return new ListTile(
|
|
leading: Icon(Icons.add),
|
|
title: Text(data[index]['title']),
|
|
subtitle: Text(data[index]['creator']),
|
|
onTap: (){
|
|
Navigator.push(context, MaterialPageRoute(
|
|
builder: (context) => ExerciseView(super.widget.token, data[index]['title'], data[index]['id'])
|
|
));
|
|
},
|
|
);
|
|
},
|
|
),
|
|
onRefresh: getWorkouts,
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: (){
|
|
Navigator.push(context, MaterialPageRoute(
|
|
builder: (context) => NewWorkoutView(super.widget.token)
|
|
));
|
|
},
|
|
child: Icon(Icons.add),
|
|
),
|
|
);
|
|
}
|
|
} |