37 lines
833 B
Dart
37 lines
833 B
Dart
|
import 'dart:async';
|
||
|
import 'package:flutter/cupertino.dart';
|
||
|
import 'package:lamiter/Class/API/api.dart';
|
||
|
|
||
|
class ImageAndLogoProvider extends ChangeNotifier {
|
||
|
String? image;
|
||
|
String? logo;
|
||
|
|
||
|
ImageAndLogoProvider() {
|
||
|
init();
|
||
|
}
|
||
|
|
||
|
Future<void> init() async {
|
||
|
image = null;
|
||
|
logo = null;
|
||
|
await refresh();
|
||
|
if (image == null || logo == null) {
|
||
|
Timer.periodic(const Duration(seconds: 3), (timer) async {
|
||
|
await refresh();
|
||
|
if (image != null && logo != null) timer.cancel();
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Future<void> refresh() async {
|
||
|
var res = await API().get_lamiter_image();
|
||
|
if (res.containsKey("success")) {
|
||
|
image = res["success"];
|
||
|
}
|
||
|
res = await API().get_lamiter_logo();
|
||
|
if (res.containsKey("success")) {
|
||
|
logo = res["success"];
|
||
|
}
|
||
|
notifyListeners();
|
||
|
}
|
||
|
}
|