Retrieve Favorites from Backend, Add Favorite Model
Co-authored-by: Reimar <mail@reim.ar>
This commit is contained in:
parent
6fd8c365f6
commit
cae02bfded
@ -1,3 +1,5 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
@ -69,7 +71,7 @@ Future<bool> isLoggedIn(BuildContext context) async {
|
||||
|
||||
try {
|
||||
String base64 = token.split('.')[1];
|
||||
base64 += List.filled(4 - base64.length % 4, '=').join();
|
||||
base64 += List.filled(base64.length % 4 == 0 ? 0 : 4 - base64.length % 4, '=').join();
|
||||
|
||||
final payload = jsonDecode(String.fromCharCodes(base64Decode(base64)));
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
@ -6,6 +9,8 @@ import 'package:mobile/register.dart';
|
||||
import 'login.dart';
|
||||
import 'base/sidemenu.dart';
|
||||
import 'profile.dart';
|
||||
import 'api.dart' as api;
|
||||
import 'models.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
@ -43,6 +48,27 @@ class MyHomePage extends StatefulWidget {
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
List<Favorite> _favorites = [];
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
|
||||
api.isLoggedIn(context).then((isLoggedIn) async {
|
||||
if (!isLoggedIn || !mounted) return;
|
||||
|
||||
final response = await api.request(context, api.ApiService.app, 'GET', '/favorites', null);
|
||||
if (response == null) return;
|
||||
log(response);
|
||||
|
||||
final List<dynamic> favorites = jsonDecode(response);
|
||||
setState(() {
|
||||
_favorites = favorites.map((favorite) => Favorite(favorite['id'], favorite['user_id'], favorite['lat'], favorite['lng'])).toList();
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SideMenu(
|
||||
|
8
Mobile/lib/models.dart
Normal file
8
Mobile/lib/models.dart
Normal file
@ -0,0 +1,8 @@
|
||||
class Favorite {
|
||||
int id;
|
||||
String userId;
|
||||
double lat;
|
||||
double lng;
|
||||
|
||||
Favorite(this.id, this.userId, this.lat, this.lng);
|
||||
}
|
@ -17,10 +17,10 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
|
||||
Future<void> _register() async {
|
||||
if (passwordInput.text != confirmPasswordInput.text) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Passwords do not match')));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Passwords do not match')));
|
||||
return;
|
||||
}
|
||||
|
||||
final result = await api.request(context, api.ApiService.auth, 'POST', '/api/Users', {
|
||||
'username': usernameInput.text,
|
||||
'email': emailInput.text,
|
||||
|
Loading…
Reference in New Issue
Block a user