FaucetHubv2/lib/gameInfo.dart

152 lines
5.5 KiB
Dart

import 'package:cached_network_image/cached_network_image.dart';
import 'package:external_app_launcher/external_app_launcher.dart';
import 'package:fhub/backend/DataManager.dart';
import 'package:fhub/backend/Dialogs.dart';
import 'package:fhub/backend/helpers.dart';
import 'package:fhub/src/CustomWidgets.dart';
import 'package:flutter/material.dart';
class GameInfoPage extends StatefulWidget {
const GameInfoPage({Key? key, required this.gameJson}) : super(key: key);
final dynamic gameJson;
@override
State<GameInfoPage> createState() => _GameInfoPageState();
}
class _GameInfoPageState extends State<GameInfoPage> with WidgetsBindingObserver {
@override
void initState() {
// TODO: implement initState
super.initState();
kickstartAnimations();
WidgetsBinding.instance.addObserver(this);
}
@override
void dispose() {
// TODO: implement dispose
super.dispose();
WidgetsBinding.instance.removeObserver(this);
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
// TODO: implement didChangeAppLifecycleState
super.didChangeAppLifecycleState(state);
if(state == AppLifecycleState.resumed){
Refresh();
}
}
void Refresh() async{
await DataManager.GrabOnce();
setState(() {
});
}
void kickstartAnimations() async {
await Future.delayed(const Duration(milliseconds: 500));
setState(() {
op1 = 0.5;
op2 = 0.5;
op3 = 0.5;
});
}
@override
Widget build(BuildContext context) {
bool linked = DataManager.LinkedGamesJson.contains(widget.gameJson);
String howto = "Install this game from playstore and login with the same google account to Link the game to this FaucetHub Automatically.\n\nTo Link manually, Navigate to 'Link to FH' in game settings, Then Enter '${DataManager.UserJson['id']}' As FH ID.\n\n Then enjoy your earnings from playing this game!";
return Scaffold(
backgroundColor: Colors.black,
body: CustomBody(child: SafeArea(child: Padding(
padding: const EdgeInsets.all(8.0),
child: SingleChildScrollView(
child: Column(children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
InkWell(child: Container(margin:EdgeInsets.all(10), child: Icon(Icons.keyboard_arrow_left,size: 50)), onTap: (){Navigator.of(context).pop();},),
GradientText(
text: widget.gameJson['name'],
gradient: LinearGradient(colors: [
Colors.white.withOpacity(0.6),
Colors.white.withOpacity(0.5),
Colors.white.withOpacity(0.2)
]),
style: TextStyle(fontSize: 33, fontWeight: FontWeight.bold),
),
Container(width: 40,)
],
),
SizedBox(height: 50,),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
width: 120,
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: CachedNetworkImage(imageUrl: widget.gameJson['icon'],)
// child: Image.network(widget.gameJson['icon'])
)),
Column(
children: [
Column(
children: [
Text("Earn"),
Text("${widget.gameJson['coin']}", style: TextStyle(fontSize: 25,fontWeight: FontWeight.bold),),
],
),SizedBox(height: 10,), Icon(Helpers.GetIconForCrypto(widget.gameJson['coin']),size: 50)
],
)
],
),
SizedBox(height: 50,),
GlassButton(onTap: ()async{
await LaunchApp.openApp(
androidPackageName: widget.gameJson['link'],
// openStore: false
);
}, child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Icon(Icons.g_mobiledata_rounded,size: 40),
Text("Open on Playstore"),
],
), width: 200,height: 50,color: Colors.greenAccent),
SizedBox(height: 35,),
Text(widget.gameJson['description'],textAlign: TextAlign.center),
SizedBox(height: 20,),
(linked) ? Container(child: Text("\nThis game is already linked to this FH account.\n\nYour Earnings from game will be accounted to this FH account",textAlign: TextAlign.center,),) :Column(
children: [
Text("Your FH ID"),
Text(DataManager.UserJson['id'], style: TextStyle(fontSize: 50, fontWeight: FontWeight.bold)),
SizedBox(height: 20,),
GlassButton(onTap: ()async{
Dialogs.showAlertDialog(context, "How to Link", howto);
}, child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Icon(Icons.help_outline_sharp,size: 30),
Text("How to Link"),
],
), width: 200,height: 50,color: Colors.lightBlueAccent)
// Text("",textAlign: TextAlign.center)
],
),
],),
),
)), context: context, onAnimEnd: (){setState(() {});}),
);
}
}