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{
|
class Hoarder{
|
||||||
|
|
||||||
static List<dynamic> GamesJson = [];
|
static List<dynamic> GamesJson = [];
|
||||||
|
static Map<String,String> Settings = {};
|
||||||
|
static List<dynamic> FeaturedGames = [];
|
||||||
|
|
||||||
static void GrabInitData() async{
|
static Future<void> GrabInitData() async{
|
||||||
var response = null;
|
|
||||||
try {
|
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());
|
Debug.LogResponse(response.body.toString());
|
||||||
GamesJson=[];
|
// Settings= jsonDecode(response.body.toString());
|
||||||
List<String> games = response.body.toString().split("<td>");
|
List jsonList = jsonDecode(response.body.toString());
|
||||||
games.forEach((game) {
|
jsonList.forEach((jsonItem) {
|
||||||
GamesJson.add(jsonDecode(game));
|
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) {
|
} catch (e) {
|
||||||
Debug.LogError("Error while loading games : $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/brains.dart';
|
||||||
import 'package:faucethub/Backend/hoarder.dart';
|
import 'package:faucethub/Backend/hoarder.dart';
|
||||||
import 'package:faucethub/Backend/login_mgr.dart';
|
import 'package:faucethub/Backend/login_mgr.dart';
|
||||||
|
|
@ -16,7 +17,7 @@ int selectedBotNavIndex = 0;
|
||||||
class _HomePageState extends State<HomePage> {
|
class _HomePageState extends State<HomePage> {
|
||||||
static List<Widget> bodyOptions = <Widget>[
|
static List<Widget> bodyOptions = <Widget>[
|
||||||
HomeWidget(),
|
HomeWidget(),
|
||||||
Text("games"),
|
GamesWidget(),
|
||||||
Text("Money!")
|
Text("Money!")
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -44,14 +45,18 @@ class _HomePageState extends State<HomePage> {
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
controller: _firstController,
|
controller: _firstController,
|
||||||
itemCount: Hoarder.GamesJson.length,
|
itemCount: Hoarder.FeaturedGames.length,
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
return Card(
|
Debug.Log(Hoarder.FeaturedGames[index]);
|
||||||
|
return InkWell(
|
||||||
|
onTap: (){},
|
||||||
|
child: Card(
|
||||||
child: ClipRRect(
|
child: ClipRRect(
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
child: Image.network(Hoarder.GamesJson[index]['icon'],
|
child: Image.network(Hoarder.FeaturedGames[index]['icon'],
|
||||||
width: 100, height: 100),
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
|
|
@ -102,7 +137,9 @@ class _HomePageState extends State<HomePage> {
|
||||||
title,
|
title,
|
||||||
style: TextStyle(fontSize: 17,fontWeight: FontWeight.bold),
|
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:faucethub/Backend/login_mgr.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
||||||
|
|
@ -22,7 +23,7 @@ class _SplashScreenState extends State<SplashScreen> {
|
||||||
|
|
||||||
void init () async{
|
void init () async{
|
||||||
int result = await LoginManager.AutoLogin();
|
int result = await LoginManager.AutoLogin();
|
||||||
|
await Hoarder.GrabInitData();
|
||||||
if(result == 0){
|
if(result == 0){
|
||||||
Navigator.of(context).pushReplacementNamed('/home');
|
Navigator.of(context).pushReplacementNamed('/home');
|
||||||
}else{
|
}else{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user