Games list wip
This commit is contained in:
parent
b20b8ac538
commit
e0ce08fa69
|
|
@ -7,20 +7,47 @@ import 'package:http/http.dart' as http;
|
|||
class Hoarder{
|
||||
|
||||
static List<dynamic> GamesJson = [];
|
||||
static Map<String,String> Settings = {};
|
||||
static List<dynamic> FeaturedGames = [];
|
||||
|
||||
static void GrabInitData() async{
|
||||
var response = null;
|
||||
static Future<void> GrabInitData() async{
|
||||
try {
|
||||
response = (await http.post(Uri.parse('${Brain.API_ENDPOINT}get_games.php')));
|
||||
var response = (await http.post(Uri.parse('${Brain.API_ENDPOINT}get_settings.php')));
|
||||
|
||||
Debug.LogError(response.body.toString());
|
||||
GamesJson=[];
|
||||
List<String> games = response.body.toString().split("<td>");
|
||||
games.forEach((game) {
|
||||
GamesJson.add(jsonDecode(game));
|
||||
Debug.LogResponse(response.body.toString());
|
||||
// Settings= jsonDecode(response.body.toString());
|
||||
List jsonList = jsonDecode(response.body.toString());
|
||||
jsonList.forEach((jsonItem) {
|
||||
Settings[jsonItem['id']] = jsonItem['value'];
|
||||
});
|
||||
|
||||
} catch (e) {
|
||||
Debug.LogError("Error while loading settings : $e");
|
||||
}
|
||||
|
||||
try {
|
||||
var response = (await http.post(Uri.parse('${Brain.API_ENDPOINT}get_games.php')));
|
||||
|
||||
Debug.LogResponse(response.body.toString());
|
||||
GamesJson=[];
|
||||
FeaturedGames = [];
|
||||
List<String> games = response.body.toString().split("<td>");
|
||||
List<String> featuredGames = Settings["featured_games"].toString().split(',');
|
||||
games.forEach((game) {
|
||||
dynamic Json = jsonDecode(game);
|
||||
String id = Json['id'];
|
||||
GamesJson.add(Json);
|
||||
|
||||
if(featuredGames.contains(id)){
|
||||
FeaturedGames.add(Json);
|
||||
}
|
||||
});
|
||||
|
||||
Debug.Log("Total games ${GamesJson.length} and ${FeaturedGames.length} featured");
|
||||
} catch (e) {
|
||||
Debug.LogError("Error while loading games : $e");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:faucethub/Backend/DebugHelper.dart';
|
||||
import 'package:faucethub/Backend/brains.dart';
|
||||
import 'package:faucethub/Backend/hoarder.dart';
|
||||
import 'package:faucethub/Backend/login_mgr.dart';
|
||||
|
|
@ -16,7 +17,7 @@ int selectedBotNavIndex = 0;
|
|||
class _HomePageState extends State<HomePage> {
|
||||
static List<Widget> bodyOptions = <Widget>[
|
||||
HomeWidget(),
|
||||
Text("games"),
|
||||
GamesWidget(),
|
||||
Text("Money!")
|
||||
];
|
||||
|
||||
|
|
@ -44,13 +45,17 @@ class _HomePageState extends State<HomePage> {
|
|||
child: ListView.builder(
|
||||
scrollDirection: Axis.horizontal,
|
||||
controller: _firstController,
|
||||
itemCount: Hoarder.GamesJson.length,
|
||||
itemCount: Hoarder.FeaturedGames.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return Card(
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Image.network(Hoarder.GamesJson[index]['icon'],
|
||||
width: 100, height: 100),
|
||||
Debug.Log(Hoarder.FeaturedGames[index]);
|
||||
return InkWell(
|
||||
onTap: (){},
|
||||
child: Card(
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Image.network(Hoarder.FeaturedGames[index]['icon'],
|
||||
width: 100, height: 100),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
|
|
@ -64,6 +69,36 @@ class _HomePageState extends State<HomePage> {
|
|||
);
|
||||
}
|
||||
|
||||
static Widget GamesWidget(){
|
||||
final ScrollController scrollController = ScrollController();
|
||||
return Container(
|
||||
child: SingleChildScrollView(
|
||||
physics: ScrollPhysics(),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Text("Linked", style: TextStyle(fontSize: 20,fontWeight: FontWeight.bold),),
|
||||
ListView.builder(
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
controller: scrollController,
|
||||
itemCount: Hoarder.GamesJson.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
Debug.Log(Hoarder.GamesJson[index]);
|
||||
return InkWell(
|
||||
onTap: (){},
|
||||
child: ListTile(
|
||||
leading: Image.network(Hoarder.GamesJson[index]['icon'],
|
||||
width: 25, height: 25),
|
||||
title: Text(Hoarder.GamesJson[index]['name']),
|
||||
),
|
||||
);
|
||||
})
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SafeArea(
|
||||
|
|
@ -102,7 +137,9 @@ class _HomePageState extends State<HomePage> {
|
|||
title,
|
||||
style: TextStyle(fontSize: 17,fontWeight: FontWeight.bold),
|
||||
),
|
||||
Icon(Icons.arrow_right_alt)
|
||||
InkWell(child: Icon(Icons.arrow_right_alt), onTap: (){
|
||||
|
||||
},)
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:faucethub/Backend/hoarder.dart';
|
||||
import 'package:faucethub/Backend/login_mgr.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
||||
|
|
@ -22,7 +23,7 @@ class _SplashScreenState extends State<SplashScreen> {
|
|||
|
||||
void init () async{
|
||||
int result = await LoginManager.AutoLogin();
|
||||
|
||||
await Hoarder.GrabInitData();
|
||||
if(result == 0){
|
||||
Navigator.of(context).pushReplacementNamed('/home');
|
||||
}else{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user