Skip to content

Commit

Permalink
Add - Pagination and Inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
GalletaOreo98 committed Apr 29, 2023
1 parent 2d24d7c commit c1bd4c1
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 122 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Custom
key
.env
private_keys.dart

# Files and directories created by pub
.dart_tool/
Expand Down
Binary file added lain_chikita/assets/images/accessories/null.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion lain_chikita/lib/global_vars.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
//User vars
int level = 0;
int progress = 0;
String username = "NULLUSER";
String username = "NULLUSER";
String accessoryName = "null";

List<Map<String, dynamic>> inventory = [
{'name': 'sunglasses', 'unlockedby': 'or3odev'},
{'name': 'sunglasses_green', 'unlockedby': 'Juan'},
{'name': 'sunglasses_red', 'unlockedby': 'elpepe'},
];
263 changes: 145 additions & 118 deletions lain_chikita/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:audioplayers/audioplayers.dart';
import 'dart:convert';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';

//My custom imports
import 'functions/encryption_functions.dart';
import 'global_vars.dart' as global;
import 'global_vars.dart';
import 'private_keys.dart';
import 'screens/inventory_screen.dart';

Future<void> main() async {
await dotenv.load(fileName: '.env');
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
void main() {
runApp(const MyApp());
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
}

class MyApp extends StatefulWidget {
Expand All @@ -28,16 +29,17 @@ class _MyAppState extends State<MyApp> {
final _player = AudioPlayer(playerId: 'btnLove');
bool showImage = false;

final secretKey = dotenv.env['SECRET_KEY'];
final secretKey = SECRET_KEY;

void _handleUserChoice(bool value) {
/* void _handleUserChoice(bool value) {
setState(() {
final jsonData = json.encode({'level': global.level, 'progress': global.progress, 'username': global.username});
final encryptedData = encryptData(jsonData, secretKey!);
decryptData(encryptedData, secretKey!);
if (global.level >= 100) showImage = value;
final jsonData = json
.encode({'level': level, 'progress': progress, 'username': username});
final encryptedData = encryptData(jsonData, secretKey);
decryptData(encryptedData, secretKey);
if (level >= 100) showImage = value;
});
}
} */

@override
void initState() {
Expand All @@ -52,34 +54,35 @@ class _MyAppState extends State<MyApp> {
Future<void> _loadProgress() async {
final prefs = await SharedPreferences.getInstance();
setState(() {
global.level = prefs.getInt('level') ?? 0;
global.progress = prefs.getInt('progress') ?? 0;
global.username = prefs.getString('username') ?? "NULLUSER";
level = prefs.getInt('level') ?? 0;
progress = prefs.getInt('progress') ?? 0;
username = prefs.getString('username') ?? "NULLUSER";
});
}

Future<void> _saveProgress() async {
final prefs = await SharedPreferences.getInstance();
await prefs.setInt('level', global.level);
await prefs.setInt('progress', global.progress);
await prefs.setString('username', global.username);
await prefs.setInt('level', level);
await prefs.setInt('progress', progress);
await prefs.setString('username', username);
}

void _incrementProgress() {
setState(() {
playBtnSound();
global.progress += 1;
if (global.progress >= _maxProgress) {
global.progress = 0;
global.level += 1;
progress += 1;
if (progress >= _maxProgress) {
progress = 0;
level += 1;
}
_saveProgress();
});
}

void _showEncryptedData() {
final jsonData = json.encode({'level': global.level, 'progress': global.progress, 'username': global.username});
final encryptedData = encryptData(jsonData, secretKey!);
final jsonData = json
.encode({'level': level, 'progress': progress, 'username': username});
final encryptedData = encryptData(jsonData, secretKey);

Fluttertoast.showToast(
msg: 'Encrypted data: $encryptedData',
Expand All @@ -92,122 +95,146 @@ class _MyAppState extends State<MyApp> {
);
}

void _updateAccessory(String newAccessoryName) {
setState(() {
accessoryName = newAccessoryName;
});
}

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Lain Chikita',
home: Scaffold(
body: Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/background.png'),
fit: BoxFit.cover,
),
),
child: Stack(
children: [
if (global.username == "NULLUSER")
Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 16),
Form(
child: TextFormField(
initialValue: global.username,
textAlign: TextAlign.center,
style: const TextStyle(color: Colors.amber),
decoration: const InputDecoration(
labelText: 'Nuevo nombre de usuario',
labelStyle: TextStyle(color: Colors.white),
floatingLabelAlignment: FloatingLabelAlignment.center,
),
onFieldSubmitted: (value) =>
setState(() => global.username = value),
),
)
],
)
else
Align(
alignment: Alignment.topCenter,
child: Column(
body: PageView(
children: [
Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/background.png'),
fit: BoxFit.cover,
),
),
child: Stack(
children: [
if (username == "NULLUSER")
Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 16),
Text(
global.username,
textAlign: TextAlign.start,
style: const TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
fontFamily: 'monospace',
color: Colors.amber,
Form(
child: TextFormField(
initialValue: username,
textAlign: TextAlign.center,
style: const TextStyle(color: Colors.amber),
decoration: const InputDecoration(
labelText: 'Nuevo nombre de usuario',
labelStyle: TextStyle(color: Colors.white),
floatingLabelAlignment:
FloatingLabelAlignment.center,
),
onFieldSubmitted: (value) =>
setState(() => username = value),
),
)
],
)),
GestureDetector(
child: Center(
)
else
Align(
alignment: Alignment.topCenter,
child: Column(
children: [
const SizedBox(height: 16),
Text(
username,
textAlign: TextAlign.start,
style: const TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
fontFamily: 'monospace',
color: Colors.amber,
),
)
],
)),
Center(
child: Image.asset(
'assets/images/lain_chikita.png',
fit: BoxFit.cover,
),
),
onTap: () {
_handleUserChoice(true);
}),
if (showImage)
Positioned(
child: Center(
child: Image.asset(
'assets/images/accessories/sunglasses.png',
fit: BoxFit.cover),
Positioned(
child: Center(
child: Image.asset(
'assets/images/accessories/$accessoryName.png',
fit: BoxFit.cover),
),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Nivel ${global.level}',
style: const TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
fontFamily: 'monospace',
color: Colors.white,
),
),
const SizedBox(height: 8.0),
SizedBox(
height: 16.0,
width: 250.0,
child: LinearProgressIndicator(
value: global.progress / _maxProgress,
backgroundColor: Colors.white,
valueColor: const AlwaysStoppedAnimation<Color>(
Color.fromARGB(255, 248, 187, 208),
Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Nivel ${level}',
style: const TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
fontFamily: 'monospace',
color: Colors.white,
),
),
),
),
const SizedBox(height: 8.0),
FloatingActionButton(
backgroundColor: Colors.pink[100],
onPressed: _incrementProgress,
child: const Icon(
Icons.favorite,
color: Colors.white,
),
const SizedBox(height: 8.0),
SizedBox(
height: 16.0,
width: 250.0,
child: LinearProgressIndicator(
value: progress / _maxProgress,
backgroundColor: Colors.white,
valueColor: const AlwaysStoppedAnimation<Color>(
Color.fromARGB(255, 248, 187, 208),
),
),
),
const SizedBox(height: 8.0),
FloatingActionButton(
backgroundColor: Colors.pink[100],
onPressed: _incrementProgress,
child: const Icon(
Icons.favorite,
color: Colors.white,
),
),
],
),
],
),
),
),
],
),
],
),
),
InventoryScreen(callback: _updateAccessory),
CustomScreen(color: Colors.blue),
],
),
),
);
}
}

class CustomScreen extends StatelessWidget {
final Color color;

const CustomScreen({required this.color});

@override
Widget build(BuildContext context) {
return Container(
color: color,
child: const Center(
child: Text('Custom Screen'),
),
);
}
}
Loading

0 comments on commit c1bd4c1

Please sign in to comment.