gameball 0.0.3
gameball: ^0.0.3 copied to clipboard
Gameball's Flutter SDK enables you to use the show Gameball player profile in your app, track app player events, integrate referrals and display Gameball's in-app push notifications.
example/lib/main.dart
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:gameball/gameball.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Gameball SDK',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Gameball SDK Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
//FOR TESTING APP ONLY
TextEditingController textFieldController1 = TextEditingController();
TextEditingController textFieldController2 = TextEditingController();
TextEditingController textFieldController3 = TextEditingController();
TextEditingController textFieldController4 = TextEditingController();
TextEditingController textFieldController5 = TextEditingController();
TextEditingController textFieldController6 = TextEditingController();
String dropdownValue = 'en';
bool isButtonEnabled = true;
String? apiKey ;
String? playerUniqueId;
String? lang;
@override
void initState() {
super.initState();
textFieldController1.text = 'df07d27a8f6f440e8a7f44195fc6c5e6';
textFieldController2.text = 'MartinSorsok';
textFieldController3.text = '{\n'
' "place_order": {\n'
' "total_amount": "100",\n'
' "category": [\n'
' "electronics",\n'
' "cosmetics"\n'
' ]\n'
' },\n'
' "review": {}\n'
'}';
textFieldController4.text = '''
{
"playerUniqueId": "${textFieldController2.text}",
"mobile": "+1234567",
"email": "jon.snow@example.com",
"playerAttributes": {
"displayName": "Jon Snow"
},
"referrerCode": null,
"levelOrder": null
}
''';
textFieldController5.text = '';
textFieldController6.text = '';
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 20.0,right: 20),
child: TextField(
controller: textFieldController1,
onChanged: (value) => checkInputs(),
decoration: InputDecoration(
labelText: 'apiKey',
),
),
),
Padding(
padding: const EdgeInsets.only(left: 20.0,right: 20),
child: TextField(
controller: textFieldController2,
onChanged: (value) => checkInputs(),
decoration: InputDecoration(
labelText: 'playerUniqueId',
),
),
),
Padding(
padding: const EdgeInsets.only(left: 20.0,right: 20),
child: TextField(
controller: textFieldController5,
onChanged: (value) => checkInputs(),
decoration: InputDecoration(
labelText: 'Platform',
),
),
),
Padding(
padding: const EdgeInsets.only(left: 20.0,right: 20),
child: TextField(
controller: textFieldController6,
onChanged: (value) => checkInputs(),
decoration: InputDecoration(
labelText: 'Shop',
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text('Language'),
DropdownButton<String>(
value: dropdownValue,
onChanged: (String? newValue) {
setState(() {
dropdownValue = newValue!;
});
},
items: <String>['en', 'ar']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
],
),
ElevatedButton(
onPressed: isButtonEnabled
? () {
apiKey = textFieldController1.text;
playerUniqueId = textFieldController2.text;
lang = dropdownValue;
final String playerDataString = textFieldController4.text;
final Map<String, dynamic> playerData = jsonDecode(playerDataString);
Gameball gameball = Gameball(
apiKey: apiKey != null ? apiKey! : '',
playerUniqueId: playerUniqueId!,
lang: lang,
playerAttributes: playerData,
platform: textFieldController5.text,
shop: textFieldController6.text,
);
gameball.openGameballView(context);
}
: null,
child: Text('Open GameBall'),
),
Padding(
padding: const EdgeInsets.only(left: 20.0,right: 20),
child: Container(
height: 300, // Adjust the height as desired
child: TextField(
controller: textFieldController3,
decoration: InputDecoration(
labelText: 'Event Data',
),
maxLines: null, // Allow multiline input
),
),
),
ElevatedButton(
onPressed: () {
sendEvent("metaData");
}
,
child: Text('Send Event GameBall'),
),
Padding(
padding: const EdgeInsets.only(left: 20.0,right: 20),
child: Container(
height: 300, // Adjust the height as desired
child: TextField(
controller: textFieldController4,
decoration: InputDecoration(
labelText: 'Player Data',
),
maxLines: null, // Allow multiline input
),
),
),
],
),
),
),
);
}
void checkInputs() {
setState(() {
isButtonEnabled = true;
// isButtonEnabled = textFieldController1.text.isNotEmpty &&
// textFieldController2.text.isNotEmpty;
});
}
void sendEvent(metaData) {
Gameball gameball = Gameball(
apiKey: textFieldController1.text,
playerUniqueId: textFieldController2.text,
lang: lang,
);
final String eventDataString = textFieldController3.text;
final Map<String, dynamic> eventData = jsonDecode(eventDataString);
gameball.sendEvent(eventData).then((response) {
print(response); // Success
}).catchError((error) {
print(error); // Error
});
}
}