Compare commits
1 Commits
master
...
developmen
Author | SHA1 | Date | |
---|---|---|---|
619907e3dc |
@ -5,9 +5,10 @@ import 'dart:async';
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
class AddExercise extends StatefulWidget{
|
class AddExercise extends StatefulWidget{
|
||||||
|
String token;
|
||||||
int workoutId;
|
int workoutId;
|
||||||
|
|
||||||
AddExercise(this.workoutId);
|
AddExercise(this.token, this.workoutId);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<StatefulWidget> createState() {
|
State<StatefulWidget> createState() {
|
||||||
@ -27,7 +28,7 @@ class AddExerciseState extends State<AddExercise>{
|
|||||||
|
|
||||||
void speichern(String id) async {
|
void speichern(String id) async {
|
||||||
if(this.anzahl != 0){
|
if(this.anzahl != 0){
|
||||||
var url = Uri.parse("http://10.16.17.18/api/add_exercise_to_workout.php?token=satbwertwhbertnwertwertghwertgwertg");
|
var url = Uri.parse("http://10.16.17.18/api/add_exercise_to_workout.php?token=" + super.widget.token);
|
||||||
var request = http.MultipartRequest("post", url);
|
var request = http.MultipartRequest("post", url);
|
||||||
Map<String, String> test = {
|
Map<String, String> test = {
|
||||||
"workout": this.widget.workoutId.toString(),
|
"workout": this.widget.workoutId.toString(),
|
||||||
|
@ -1,6 +1,14 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
class CustomDrawer extends StatelessWidget{
|
class CustomDrawer extends StatelessWidget{
|
||||||
|
void logout() async {
|
||||||
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
|
prefs.remove("api_key");
|
||||||
|
SystemChannels.platform.invokeMethod('SystemNavigator.pop');
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// TODO: implement build
|
// TODO: implement build
|
||||||
@ -40,7 +48,9 @@ class CustomDrawer extends StatelessWidget{
|
|||||||
ListTile(
|
ListTile(
|
||||||
leading: Icon(Icons.exit_to_app),
|
leading: Icon(Icons.exit_to_app),
|
||||||
title: Text('Logout'),
|
title: Text('Logout'),
|
||||||
onTap: () => {Navigator.of(context).pop()},
|
onTap: () {
|
||||||
|
logout();
|
||||||
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -6,10 +6,11 @@ import 'dart:async';
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
class ExerciseView extends StatefulWidget{
|
class ExerciseView extends StatefulWidget{
|
||||||
|
String token;
|
||||||
String title;
|
String title;
|
||||||
String id;
|
String id;
|
||||||
|
|
||||||
ExerciseView(this.title, this.id);
|
ExerciseView(this.token, this.title, this.id);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<StatefulWidget> createState() {
|
State<StatefulWidget> createState() {
|
||||||
@ -24,7 +25,7 @@ class ExerciseViewState extends State<ExerciseView>{
|
|||||||
|
|
||||||
Future<List> getWorkouts() async {
|
Future<List> getWorkouts() async {
|
||||||
var response = await http.get(
|
var response = await http.get(
|
||||||
"http://10.16.17.18/api/workout.php?token=satbwertwhbertnwertwertghwertgwertg&workout="+this.widget.id,
|
"http://10.16.17.18/api/workout.php?token=" + super.widget.token + "&workout="+this.widget.id,
|
||||||
headers: {
|
headers: {
|
||||||
"Accept": "application/json"
|
"Accept": "application/json"
|
||||||
}
|
}
|
||||||
@ -75,7 +76,7 @@ class ExerciseViewState extends State<ExerciseView>{
|
|||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
onPressed: (){
|
onPressed: (){
|
||||||
Navigator.push(context, MaterialPageRoute(
|
Navigator.push(context, MaterialPageRoute(
|
||||||
builder: (context) => AddExercise(int.parse(this.widget.id))
|
builder: (context) => AddExercise(super.widget.token, int.parse(this.widget.id))
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
child: Icon(Icons.add),
|
child: Icon(Icons.add),
|
||||||
|
@ -2,7 +2,19 @@ import 'package:fitnessapp/Views/custom_drawer.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'workouts_view.dart';
|
import 'workouts_view.dart';
|
||||||
|
|
||||||
class HomescreenView extends StatelessWidget{
|
class HomescreenView extends StatefulWidget{
|
||||||
|
String token;
|
||||||
|
|
||||||
|
HomescreenView(this.token);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<StatefulWidget> createState() {
|
||||||
|
// TODO: implement createState
|
||||||
|
return new HomescreenViewState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class HomescreenViewState extends State<HomescreenView>{
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// TODO: implement build
|
// TODO: implement build
|
||||||
@ -11,7 +23,7 @@ class HomescreenView extends StatelessWidget{
|
|||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text("Workouts"),
|
title: Text("Workouts"),
|
||||||
),
|
),
|
||||||
body: WorkoutsView(),
|
body: WorkoutsView(super.widget.token),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
96
lib/Views/login_view.dart
Normal file
96
lib/Views/login_view.dart
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
import 'package:fitnessapp/Views/custom_drawer.dart';
|
||||||
|
import 'package:fitnessapp/Views/homescreen.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'workouts_view.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'dart:async';
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
class LoginView extends StatefulWidget{
|
||||||
|
@override
|
||||||
|
State<StatefulWidget> createState() {
|
||||||
|
// TODO: implement createState
|
||||||
|
return new _LoginViewState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _LoginViewState extends State<LoginView>{
|
||||||
|
final usernameController = TextEditingController();
|
||||||
|
final passwordController = TextEditingController();
|
||||||
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
|
||||||
|
void _saveToken(String token) async{
|
||||||
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
|
await prefs.setString("api_key", token);
|
||||||
|
|
||||||
|
String test = await prefs.getString("api_key");
|
||||||
|
print(test);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _getToken() async {
|
||||||
|
var url = Uri.parse("http://10.16.17.18/api/login.php");
|
||||||
|
var request = http.MultipartRequest("post", url);
|
||||||
|
Map<String, String> test = {
|
||||||
|
"username": usernameController.value.text,
|
||||||
|
"password": passwordController.value.text
|
||||||
|
};
|
||||||
|
request.fields.addAll(test);
|
||||||
|
var response = await request.send();
|
||||||
|
if(response.statusCode == 200){
|
||||||
|
String text = await response.stream.bytesToString();
|
||||||
|
await _saveToken(text);
|
||||||
|
Navigator.push(context, MaterialPageRoute(
|
||||||
|
builder: (context) => HomescreenView(text)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
// TODO: implement build
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text("Login"),
|
||||||
|
),
|
||||||
|
body: Form(
|
||||||
|
key: _formKey,
|
||||||
|
child: Column(
|
||||||
|
children: <Widget>[
|
||||||
|
TextFormField(
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: "username"
|
||||||
|
),
|
||||||
|
controller: usernameController,
|
||||||
|
validator: (value){
|
||||||
|
if(value.isEmpty){
|
||||||
|
return "bitte gib einen Nutzername ein";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
TextFormField(
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: "password"
|
||||||
|
),
|
||||||
|
controller: passwordController,
|
||||||
|
validator: (value){
|
||||||
|
if(value.isEmpty){
|
||||||
|
return "bitte gib Passwort ein";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
obscureText: true,
|
||||||
|
),
|
||||||
|
RaisedButton(
|
||||||
|
child: Text("Login"),
|
||||||
|
onPressed: (){
|
||||||
|
if(_formKey.currentState.validate()){
|
||||||
|
_getToken();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,10 @@ import 'dart:async';
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
class NewWorkoutView extends StatefulWidget{
|
class NewWorkoutView extends StatefulWidget{
|
||||||
|
String token;
|
||||||
|
|
||||||
|
NewWorkoutView(this.token);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<StatefulWidget> createState() {
|
State<StatefulWidget> createState() {
|
||||||
return new NewWorkoutViewState();
|
return new NewWorkoutViewState();
|
||||||
@ -22,10 +26,7 @@ class NewWorkoutViewState extends State<NewWorkoutView>{
|
|||||||
|
|
||||||
void speichern() async {
|
void speichern() async {
|
||||||
if(this.name != ''){
|
if(this.name != ''){
|
||||||
FormData data = new FormData.fromMap({
|
var url = Uri.parse("http://10.16.17.18/api/new_workout.php?token=" + super.widget.token);
|
||||||
"name": "Hallo Welt"
|
|
||||||
});
|
|
||||||
var url = Uri.parse("http://10.16.17.18/api/new_workout.php?token=satbwertwhbertnwertwertghwertgwertg");
|
|
||||||
var request = http.MultipartRequest("post", url);
|
var request = http.MultipartRequest("post", url);
|
||||||
Map<String, String> test = {"name": name};
|
Map<String, String> test = {"name": name};
|
||||||
request.fields.addAll(test);
|
request.fields.addAll(test);
|
||||||
@ -38,7 +39,7 @@ class NewWorkoutViewState extends State<NewWorkoutView>{
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text("Füge eine Übung hinzu"),
|
title: Text("Neues Workout"),
|
||||||
),
|
),
|
||||||
body: Column(
|
body: Column(
|
||||||
mainAxisSize: MainAxisSize.max,
|
mainAxisSize: MainAxisSize.max,
|
||||||
@ -46,7 +47,6 @@ class NewWorkoutViewState extends State<NewWorkoutView>{
|
|||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.all(8),
|
padding: EdgeInsets.all(8),
|
||||||
child: TextField(
|
child: TextField(
|
||||||
keyboardType: TextInputType.number,
|
|
||||||
autocorrect: true,
|
autocorrect: true,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
|
@ -6,6 +6,11 @@ import 'dart:async';
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
class WorkoutsView extends StatefulWidget{
|
class WorkoutsView extends StatefulWidget{
|
||||||
|
String token;
|
||||||
|
|
||||||
|
|
||||||
|
WorkoutsView(this.token);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<StatefulWidget> createState() {
|
State<StatefulWidget> createState() {
|
||||||
// TODO: implement createState
|
// TODO: implement createState
|
||||||
@ -18,7 +23,7 @@ class WorkoutsViewState extends State<WorkoutsView>{
|
|||||||
|
|
||||||
Future<List> getWorkouts() async {
|
Future<List> getWorkouts() async {
|
||||||
var response = await http.get(
|
var response = await http.get(
|
||||||
"http://10.16.17.18/api/index.php?token=satbwertwhbertnwertwertghwertgwertg",
|
"http://10.16.17.18/api/index.php?token=" + super.widget.token,
|
||||||
headers: {
|
headers: {
|
||||||
"Accept": "application/json"
|
"Accept": "application/json"
|
||||||
}
|
}
|
||||||
@ -49,7 +54,7 @@ class WorkoutsViewState extends State<WorkoutsView>{
|
|||||||
subtitle: Text(data[index]['creator']),
|
subtitle: Text(data[index]['creator']),
|
||||||
onTap: (){
|
onTap: (){
|
||||||
Navigator.push(context, MaterialPageRoute(
|
Navigator.push(context, MaterialPageRoute(
|
||||||
builder: (context) => ExerciseView(data[index]['title'], data[index]['id'])
|
builder: (context) => ExerciseView(super.widget.token, data[index]['title'], data[index]['id'])
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -60,7 +65,7 @@ class WorkoutsViewState extends State<WorkoutsView>{
|
|||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
onPressed: (){
|
onPressed: (){
|
||||||
Navigator.push(context, MaterialPageRoute(
|
Navigator.push(context, MaterialPageRoute(
|
||||||
builder: (context) => NewWorkoutView()
|
builder: (context) => NewWorkoutView(super.widget.token)
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
child: Icon(Icons.add),
|
child: Icon(Icons.add),
|
||||||
|
@ -1,33 +1,34 @@
|
|||||||
import 'package:fitnessapp/Views/homescreen.dart';
|
import 'package:fitnessapp/Views/homescreen.dart';
|
||||||
|
import 'package:fitnessapp/Views/login_view.dart';
|
||||||
|
import 'package:fitnessapp/Views/new_workout_view.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
void main() => runApp(MyApp());
|
void main() async {
|
||||||
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
|
String apiKey = await prefs.getString('api_key');
|
||||||
|
runApp(MaterialApp(
|
||||||
|
title: 'Flutter Demo',
|
||||||
|
theme: ThemeData(
|
||||||
|
// Define the default brightness and colors.
|
||||||
|
brightness: Brightness.dark,
|
||||||
|
primaryColor: Colors.lightBlue[800],
|
||||||
|
accentColor: Colors.cyan[600],
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
// Define the default font family.
|
||||||
// This widget is the root of your application.
|
fontFamily: 'Verdana',
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
title: 'Flutter Demo',
|
|
||||||
theme: ThemeData(
|
|
||||||
// Define the default brightness and colors.
|
|
||||||
brightness: Brightness.dark,
|
|
||||||
primaryColor: Colors.lightBlue[800],
|
|
||||||
accentColor: Colors.cyan[600],
|
|
||||||
|
|
||||||
// Define the default font family.
|
// Define the default TextTheme. Use this to specify the default
|
||||||
fontFamily: 'Verdana',
|
// text styling for headlines, titles, bodies of text, and more.
|
||||||
|
textTheme: TextTheme(
|
||||||
// Define the default TextTheme. Use this to specify the default
|
headline: TextStyle(fontSize: 72.0, fontWeight: FontWeight.bold),
|
||||||
// text styling for headlines, titles, bodies of text, and more.
|
title: TextStyle(fontSize: 36.0, fontStyle: FontStyle.italic),
|
||||||
textTheme: TextTheme(
|
body1: TextStyle(fontSize: 14.0, fontFamily: 'Verdana'),
|
||||||
headline: TextStyle(fontSize: 72.0, fontWeight: FontWeight.bold),
|
|
||||||
title: TextStyle(fontSize: 36.0, fontStyle: FontStyle.italic),
|
|
||||||
body1: TextStyle(fontSize: 14.0, fontFamily: 'Verdana'),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
home: HomescreenView(),
|
),
|
||||||
);
|
home: apiKey == null ? LoginView() : HomescreenView(apiKey),
|
||||||
}
|
)
|
||||||
}
|
);
|
||||||
|
}
|
36
pubspec.lock
36
pubspec.lock
@ -81,6 +81,11 @@ packages:
|
|||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
flutter_web_plugins:
|
||||||
|
dependency: transitive
|
||||||
|
description: flutter
|
||||||
|
source: sdk
|
||||||
|
version: "0.0.0"
|
||||||
http:
|
http:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -129,7 +134,7 @@ packages:
|
|||||||
name: pedantic
|
name: pedantic
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.8.0+1"
|
version: "1.9.0"
|
||||||
petitparser:
|
petitparser:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -144,6 +149,34 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.5"
|
version: "2.0.5"
|
||||||
|
shared_preferences:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: shared_preferences
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.5.6+3"
|
||||||
|
shared_preferences_macos:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: shared_preferences_macos
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.0.1+6"
|
||||||
|
shared_preferences_platform_interface:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: shared_preferences_platform_interface
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.3"
|
||||||
|
shared_preferences_web:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: shared_preferences_web
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.1.2+4"
|
||||||
sky_engine:
|
sky_engine:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description: flutter
|
description: flutter
|
||||||
@ -214,3 +247,4 @@ packages:
|
|||||||
version: "3.5.0"
|
version: "3.5.0"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">2.4.0 <3.0.0"
|
dart: ">2.4.0 <3.0.0"
|
||||||
|
flutter: ">=1.12.13+hotfix.4 <2.0.0"
|
||||||
|
@ -25,6 +25,7 @@ dependencies:
|
|||||||
cupertino_icons: ^0.1.2
|
cupertino_icons: ^0.1.2
|
||||||
http:
|
http:
|
||||||
dio:
|
dio:
|
||||||
|
shared_preferences:
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
@ -13,7 +13,7 @@ import 'package:fitnessapp/main.dart';
|
|||||||
void main() {
|
void main() {
|
||||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||||
// Build our app and trigger a frame.
|
// Build our app and trigger a frame.
|
||||||
await tester.pumpWidget(MyApp());
|
/*await tester.pumpWidget(MyApp());
|
||||||
|
|
||||||
// Verify that our counter starts at 0.
|
// Verify that our counter starts at 0.
|
||||||
expect(find.text('0'), findsOneWidget);
|
expect(find.text('0'), findsOneWidget);
|
||||||
@ -25,6 +25,6 @@ void main() {
|
|||||||
|
|
||||||
// Verify that our counter has incremented.
|
// Verify that our counter has incremented.
|
||||||
expect(find.text('0'), findsNothing);
|
expect(find.text('0'), findsNothing);
|
||||||
expect(find.text('1'), findsOneWidget);
|
expect(find.text('1'), findsOneWidget);*/
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user