I'm tring to make data folder, but cannot add API to it. I can get results but can't add it to the List.
How can i get this variable outside of the Function? This .dart file only contain List, nothing more.
I want to get counts from the api and use them in my model list. This dart page is made for models only.
import 'package:selam/constants.dart';
import 'package:flutter/material.dart';
import 'dart:convert' as convert;
import 'package:http/http.dart' as http;
import 'package:selam/main.dart';
import 'package:shared_preferences/shared_preferences.dart';
class CloudStorageInfo {
final String? title, totalStorage;
final int? numOfFiles, percentage;
final Color? color;
final IconData? svgSrc;
String? patientPhone;
CloudStorageInfo({
this.svgSrc,
this.title,
this.totalStorage,
this.numOfFiles,
this.percentage,
this.patientPhone,
this.color,
});
}
Future<List<dynamic>> wiki() async {
var response = await http.get(Uri.https('www.h****y.com', '/wc-api/v3/orders/count?consumer_key=ck_3*3&consumer_secret=cs_6*0'));
print(response);
if (response.statusCode == 200) {
var jsonResponse =
convert.jsonDecode(response.body) as Map<String, dynamic>;
print(jsonResponse);
return jsonResponse['count'];
} else {
print('Request failed with status: ${response.statusCode}.');
return [];
}
}
List demoMyFiles = [
CloudStorageInfo(
title: "Kazanç",
numOfFiles: 1328,
svgSrc: Icons.monetization_on_outlined,
totalStorage: "",
color: primaryColor,
percentage: 35,
),
CloudStorageInfo(
title: "Siparişler",
numOfFiles: int.parse(wiki().toString()),
svgSrc: Icons.shopping_bag_outlined,
totalStorage: "",
color: Color(0xFFFFA113),
percentage: 35,
),
CloudStorageInfo(
title: "Kullanıcılar",
numOfFiles: 1328,
svgSrc: Icons.supervised_user_circle_outlined,
totalStorage: "",
color: Color(0xFFA4CDFF),
percentage: 10,
),
CloudStorageInfo(
title: "İncelemeler",
numOfFiles: 5328,
svgSrc: Icons.reviews_outlined,
totalStorage: "",
color: Color(0xFF007EE5),
percentage: 78,
),
];