36 lines
1.1 KiB
Dart
36 lines
1.1 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:frontend_splatournament_manager/models/tournament.dart';
|
|
import 'package:http/http.dart' as http;
|
|
|
|
class StateProvider extends ChangeNotifier {
|
|
static const String baseUrl = "http://10.0.2.2:3000";
|
|
ThemeMode _themeMode = ThemeMode.system;
|
|
|
|
ThemeMode get theme => _themeMode;
|
|
|
|
void setTheme(ThemeMode mode) {
|
|
_themeMode = mode;
|
|
notifyListeners();
|
|
}
|
|
List<Tournament>? _availableTournaments;
|
|
void notifyState(){
|
|
notifyListeners();
|
|
}
|
|
Future<List<Tournament>> fetchAvailableTournaments() async {
|
|
try {
|
|
var response = await http.get(Uri.parse('$baseUrl/tournaments'));
|
|
if (response.statusCode == 200) {
|
|
final List<dynamic> list = json.decode(response.body);
|
|
_availableTournaments = list.map((json) => Tournament.fromJson(json)).toList();
|
|
return _availableTournaments!;
|
|
}
|
|
} catch (e) {
|
|
_availableTournaments = null;
|
|
return Future.error(e);
|
|
}
|
|
return[];
|
|
}
|
|
List<Tournament> get availableTournaments => _availableTournaments ?? [];
|
|
} |