From c1bd4c172c6f1c6577e8932027dc161b1fb2ed43 Mon Sep 17 00:00:00 2001 From: GalletaOreo98 Date: Sat, 29 Apr 2023 16:17:20 -0600 Subject: [PATCH] Add - Pagination and Inventory --- .gitignore | 2 +- .../assets/images/accessories/null.png | Bin 0 -> 2201 bytes .../images/accessories/sunglasses_green.png | Bin 0 -> 3023 bytes .../images/accessories/sunglasses_red.png | Bin 0 -> 3344 bytes lain_chikita/lib/global_vars.dart | 9 +- lain_chikita/lib/main.dart | 263 ++++++++++-------- .../lib/screens/inventory_screen.dart | 40 +++ lain_chikita/pubspec.yaml | 5 +- 8 files changed, 197 insertions(+), 122 deletions(-) create mode 100644 lain_chikita/assets/images/accessories/null.png create mode 100644 lain_chikita/assets/images/accessories/sunglasses_green.png create mode 100644 lain_chikita/assets/images/accessories/sunglasses_red.png create mode 100644 lain_chikita/lib/screens/inventory_screen.dart diff --git a/.gitignore b/.gitignore index 6a63a56..4ffec66 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ # Custom key -.env +private_keys.dart # Files and directories created by pub .dart_tool/ diff --git a/lain_chikita/assets/images/accessories/null.png b/lain_chikita/assets/images/accessories/null.png new file mode 100644 index 0000000000000000000000000000000000000000..949b1c858fcefcdda1277774b985a390495ba8e6 GIT binary patch literal 2201 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5Q#jaw)OqozT0l--rn7TEW^ytEgT}NB1n%Qx+Mdd>a7DbYC#zFz^A}g%EGYe8%GLj3Td;tf_`E3H8(rqDx4-sm z)7hhM^WX$ytNxUEt3E7#RMHwRYJKtt%a73W0lV6QP1mH$c<+d}$Vu(~b-wb7ZlN<2N^_TD z{Ip4@{+7>MXK54iQm)78aP#xMUz`%S?M~18UihGLetSSUfBMc<_WG8+dpqOSWj(ab zh;5(zdDXOAZI^jp?AdJU{(IW1lwZEW^ZFO2%H3MGAamoStLLrUw@-+ftiG#dZtRQ6 zf7g1)D{aV->QR!t1B?L90*}aI1_o{+5N5n|x9$%E1KUMU7srr_xVJYia6U4dZ^Ba<{YM?-J> z`cfwEyG(a_i@#)ldGXm=ezEoH{hha`|C#)dSE1fbOC>-}f#Fn!u8%^z1H+T^9<3~= zSXdk+*S2y#0c!svxpIQT%mZTE8Ln<;_K)9lTJ3vdt9yR1+x-6wjy0Y47#_JVabPNC zVp?$S+9{SttSkgTe~DWM4f*rVAe literal 0 HcmV?d00001 diff --git a/lain_chikita/assets/images/accessories/sunglasses_green.png b/lain_chikita/assets/images/accessories/sunglasses_green.png new file mode 100644 index 0000000000000000000000000000000000000000..9f92e856f37f7cdb65f3e31cd9d4a8d1422735d9 GIT binary patch literal 3023 zcmeHJ|3A}-AAfK2WehhTU*`L$q>iHNoU18h=38cmKDfJZWHmGt^DTxn$+x5sXG2oH z4m%@ZYl>4RDNY%UwZtg$bzh8gkH>xfhWq@`53k4b`Fj5N`ufbmVVzZ#^^^esP<3@d zdjSAwhl0*P6?R|<@&4b*U7EEbEWp}TxpWS>qA{r67<$b(`0Qf6y8oh%i9<}$8)-ED zdFYIa=w55*`#+u8PqluHx6mss3xvv3@88Q*!w_D?j8U;C_lo1XcvIeMiMTZhnMb>m z@FpsD$yzyomgx;QLQsD^@cNp~74BLN)1u4LcItP~70a8{x}`h(m@9!=r~#3j=+qFd zlj3dNaMr-RBk=o(&}_+2!iYyYhWMRHn>*g-V018Asi5k2Wq)NAw?S7tS-OkYqr1!> zejn-0QFkuQiC07)aPxJn+uvytSajp5ERNcA#MWodDCb1)0fYyyC?qAS|L zCqCfgBuF#ct-+`u<~vA zI+#9mqT}Lf=qpbc+ektBr&wTjbi#48Zcmhnl{B(qQ9lAK*F;a1pOWNtQ#GL400NX2 zZh;GjTajJfZXq~txN!cwko4{{T#c9k5A>Mn>S5I4^AF*WOUwL?rKN$5LGX*G`vgVwwbrccw}Y26Jyx*H2!8jHWMP=% z%zG5l&}YC1Rn#;$v!cmYh#zMaZqHlxjE@k==2uNGJS#qInN;J%!DtfZGW0+ zudamj`{f?N-#1)G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{vQt9lnruFiJ>EBPZ$81!Da7MyP<_uPt*@TzulW%uRV!S>+=s9GY=g~d6;t`M5 zqNtS?&{m3;k7q-8oOAR!DVi<_qeO z&k*dtV*5Xs4kFDSz4tImFWNILb3^}!!hY!cU)T2!1phSzDLbL7>LH*7TuZwbZR^nn NoE_cJmG*(D{{v$AR1*LI literal 0 HcmV?d00001 diff --git a/lain_chikita/lib/global_vars.dart b/lain_chikita/lib/global_vars.dart index 84ff9e9..1383b23 100644 --- a/lain_chikita/lib/global_vars.dart +++ b/lain_chikita/lib/global_vars.dart @@ -1,4 +1,11 @@ //User vars int level = 0; int progress = 0; -String username = "NULLUSER"; \ No newline at end of file +String username = "NULLUSER"; +String accessoryName = "null"; + +List> inventory = [ + {'name': 'sunglasses', 'unlockedby': 'or3odev'}, + {'name': 'sunglasses_green', 'unlockedby': 'Juan'}, + {'name': 'sunglasses_red', 'unlockedby': 'elpepe'}, +]; \ No newline at end of file diff --git a/lain_chikita/lib/main.dart b/lain_chikita/lib/main.dart index 9a7ce18..4a00d9e 100644 --- a/lain_chikita/lib/main.dart +++ b/lain_chikita/lib/main.dart @@ -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 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 { @@ -28,16 +29,17 @@ class _MyAppState extends State { 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() { @@ -52,34 +54,35 @@ class _MyAppState extends State { Future _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 _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', @@ -92,122 +95,146 @@ class _MyAppState extends State { ); } + 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.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.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'), + ), + ); + } +} diff --git a/lain_chikita/lib/screens/inventory_screen.dart b/lain_chikita/lib/screens/inventory_screen.dart new file mode 100644 index 0000000..c8b6d48 --- /dev/null +++ b/lain_chikita/lib/screens/inventory_screen.dart @@ -0,0 +1,40 @@ +import 'package:flutter/material.dart'; + +import '../global_vars.dart'; + +class InventoryScreen extends StatefulWidget { + final Function callback; + const InventoryScreen({super.key, required this.callback}); + + @override + MyWidgetState createState() => MyWidgetState(); +} + +class MyWidgetState extends State { + void _incrementCounter(String newAccessoryName) { + setState(() { + accessoryName = newAccessoryName; + }); + // Llamada a la funciĆ³n de callback + widget.callback(accessoryName); + } + + @override + Widget build(BuildContext context) { + return Container( + child: ListView.builder( + itemCount: inventory.length, + itemBuilder: (BuildContext context, int index) { + return InkWell( + onTap: () { + _incrementCounter(inventory[index]['name']); + }, + child: ListTile( + title: Text(inventory[index]['name']), + subtitle: Text('By: ${inventory[index]['unlockedby']}'), + )); + }, + ), + ); + } +} diff --git a/lain_chikita/pubspec.yaml b/lain_chikita/pubspec.yaml index f42b2d1..dc47e12 100644 --- a/lain_chikita/pubspec.yaml +++ b/lain_chikita/pubspec.yaml @@ -38,7 +38,6 @@ dependencies: audioplayers: ^4.0.1 encrypt: ^5.0.1 fluttertoast: ^8.2.1 - flutter_dotenv: ^5.0.2 dev_dependencies: flutter_test: @@ -65,9 +64,11 @@ flutter: assets: - assets/images/lain_chikita.png - assets/images/background.png + - assets/images/accessories/null.png - assets/images/accessories/sunglasses.png + - assets/images/accessories/sunglasses_green.png + - assets/images/accessories/sunglasses_red.png - assets/audio/btn_sound.mp3 - - .env # To add assets to your application, add an assets section, like this: # assets: