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 0000000..949b1c8 Binary files /dev/null and b/lain_chikita/assets/images/accessories/null.png differ 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 0000000..9f92e85 Binary files /dev/null and b/lain_chikita/assets/images/accessories/sunglasses_green.png differ diff --git a/lain_chikita/assets/images/accessories/sunglasses_red.png b/lain_chikita/assets/images/accessories/sunglasses_red.png new file mode 100644 index 0000000..ff4ed9f Binary files /dev/null and b/lain_chikita/assets/images/accessories/sunglasses_red.png differ 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: