Pantalla de juego diseñada. Teclado numérico y botón de pausa dibujados

parent 82f19819
...@@ -18,7 +18,7 @@ pluginManagement { ...@@ -18,7 +18,7 @@ pluginManagement {
plugins { plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0" id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.1.0" apply false id "com.android.application" version "8.2.1" apply false
id "org.jetbrains.kotlin.android" version "1.8.22" apply false id "org.jetbrains.kotlin.android" version "1.8.22" apply false
} }
......
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:peponator/peponator_app.dart';
void main() { void main() {
runApp(const MyApp()); runApp(const PeponatorApp());
} }
\ No newline at end of file
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// TRY THIS: Try running your application with "flutter run". You'll see
// the application has a purple toolbar. Then, without quitting the app,
// try changing the seedColor in the colorScheme below to Colors.green
// and then invoke "hot reload" (save your changes or press the "hot
// reload" button in a Flutter-supported IDE, or press "r" if you used
// the command line to start the app).
//
// Notice that the counter didn't reset back to zero; the application
// state is not lost during the reload. To reset the state, use hot
// restart instead.
//
// This works for code too, not just values: Most code changes can be
// tested with just a hot reload.
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// TRY THIS: Try changing the color here to a specific color (to
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
// change color while the other colors stay the same.
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
//
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
// action in the IDE, or press "p" in the console), to see the
// wireframe for each widget.
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
export 'pantalla_juego.dart';
\ No newline at end of file
import 'package:flutter/material.dart';
import 'dart:math';
import 'package:peponator/widgets/teclado_numerico.dart';
class PantallaJuego extends StatefulWidget {
const PantallaJuego({super.key});
@override
State<PantallaJuego> createState() => _PantallaJuegoState();
}
class _PantallaJuegoState extends State<PantallaJuego> {
late final TextEditingController controller = TextEditingController();
late final int numeroAdivinar;
late final List<String> pistas;
late int limiteInferior;
late int limiteSuperior;
int? numeroEscogido;
@override
void initState() {
super.initState();
Random random = new Random();
limiteInferior = 0;
// TODO: Cargar el límite superior
limiteSuperior = 100;
numeroAdivinar = random.nextInt(limiteSuperior)+1;
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Stack(
children: [
Positioned(
top: 0,
right: 10,
child: ElevatedButton(
onPressed: () {
// TODO: Abrir el diálogo
},
style: ButtonStyle(
elevation: WidgetStatePropertyAll<double>(5.0),
shape: WidgetStatePropertyAll<OutlinedBorder>(CircleBorder()),
padding: WidgetStatePropertyAll<EdgeInsets>(
EdgeInsets.all(16.0)
),
side: WidgetStatePropertyAll<BorderSide>(
BorderSide(
width: 2.0,
color: Colors.black12
)
)
),
child: Icon(
Icons.pause,
size: 28.0,
)
)
),
Positioned(
bottom: 0,
left: 0,
child: _buildTeclado()
)
],
)
),
);
}
Widget _buildTeclado() {
final fullWidth = MediaQuery.of(context).size.width;
final fullHeight = 360.0;
return Container(
//color: Theme.of(context).colorScheme.surfaceDim,
child: Column(
children: [
SizedBox(
width: fullWidth,
height: fullHeight/4,
child: Row(
children: [
SizedBox(
width: fullWidth/4,
child: IconButton(
onPressed: () {},
style: ButtonStyle(
shape: WidgetStatePropertyAll<OutlinedBorder>(CircleBorder()),
padding: WidgetStatePropertyAll<EdgeInsets>(
EdgeInsets.all(16.0)
),
side: WidgetStatePropertyAll<BorderSide>(
BorderSide(
width: 2.0,
color: Colors.black12
)
)
),
icon: Badge(
label: Text(
'!',
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: Colors.white,
fontWeight: FontWeight.bold
),
),
backgroundColor: Colors.red,
offset: const Offset(16.0, -16.0),
child: const Icon(
Icons.lightbulb,
size: 35.0,
),
)
),
),
SizedBox(
width: fullWidth*3/4,
child: ExcludeFocus(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15.0),
child: TextField(
controller: controller,
enableInteractiveSelection: false,
textAlign: TextAlign.end,
decoration: const InputDecoration(
hintText: 'Tu respuesta...',
border: OutlineInputBorder()
),
),
),
),
)
],
),
),
SizedBox(
width: fullWidth,
height: fullHeight*3/4,
child: Row(
children: [
SizedBox(
width: fullWidth/4,
child: Placeholder(),
),
SizedBox(
width: fullWidth*3/4,
child: TecladoNumerico(controller: controller),
)
],
),
)
],
),
);
}
}
import 'package:flutter/material.dart';
import 'package:peponator/paginas/pantalla_juego.dart';
class PeponatorApp extends StatelessWidget {
const PeponatorApp({super.key});
@override
Widget build(BuildContext context) {
// TODO: Escribir en preferencias los ajustes por defecto (presumo el modo Fácil)
return MaterialApp(
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.cyan)
),
darkTheme: ThemeData.dark(),
themeMode: ThemeMode.system,
home: PantallaJuego(),
);
}
}
import 'package:flutter/material.dart';
class TecladoNumerico extends StatelessWidget {
final TextEditingController controller;
final VoidCallback? onEnterPress;
final Color numberBackgroundColor;
final Color backspaceBackgroundColor;
final Color enterBackgroundColor;
final Color numberColor;
final Color backspaceColor;
final Color enterColor;
const TecladoNumerico({
Key? key,
required this.controller,
this.onEnterPress,
this.numberBackgroundColor = Colors.cyan,
this.backspaceBackgroundColor = Colors.red,
this.enterBackgroundColor = Colors.lightGreen,
this.numberColor = const Color.fromARGB(255, 255, 255, 255),
this.backspaceColor = const Color.fromARGB(255, 255, 255, 255),
this.enterColor = const Color.fromARGB(255, 255, 255, 255),
}): super(key: key);
@override
Widget build(BuildContext context) {
return Column(
children: [
Expanded(
child: Row(
children: [
_buildNumberButton(context, 1),
_buildNumberButton(context, 2),
_buildNumberButton(context, 3),
],
),
),
Expanded(
child: Row(
children: [
_buildNumberButton(context, 4),
_buildNumberButton(context, 5),
_buildNumberButton(context, 6),
],
),
),
Expanded(
child: Row(
children: [
_buildNumberButton(context, 7),
_buildNumberButton(context, 8),
_buildNumberButton(context, 9),
],
),
),
Expanded(
child: Row(
children: [
_buildBackspaceButton(context),
_buildNumberButton(context, 0),
_buildEnterButton(context)
],
),
),
]
);
}
Widget _buildNumberButton(BuildContext context, int number){
return Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
style: TextButton.styleFrom(
backgroundColor: numberBackgroundColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(16.0))
),
),
onPressed: () {
controller.text += number.toString();
},
child: Text(
number.toString(),
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: numberColor,
fontWeight: FontWeight.bold,
fontSize: 24
),
)
),
)
);
}
Widget _buildBackspaceButton(BuildContext context){
return Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
style: TextButton.styleFrom(
backgroundColor: backspaceBackgroundColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(16.0))
)
),
onPressed: () {
if(controller.text.isNotEmpty){
controller.text = controller.text.substring(0, controller.text.length-1);
}
},
child: Icon(
Icons.backspace_outlined,
color: backspaceColor,
size: 24
)
),
)
);
}
Widget _buildEnterButton(BuildContext context){
return Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
style: TextButton.styleFrom(
backgroundColor: enterBackgroundColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(16.0))
)
),
onPressed: onEnterPress,
child: Icon(
Icons.keyboard_return,
color: enterColor,
size: 24
)
),
)
);
}
}
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
import FlutterMacOS import FlutterMacOS
import Foundation import Foundation
import shared_preferences_foundation
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
} }
...@@ -57,6 +57,22 @@ packages: ...@@ -57,6 +57,22 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.3.2" version: "1.3.2"
ffi:
dependency: transitive
description:
name: ffi
sha256: "289279317b4b16eb2bb7e271abccd4bf84ec9bdcbe999e278a94b804f5630418"
url: "https://pub.dev"
source: hosted
version: "2.1.4"
file:
dependency: transitive
description:
name: file
sha256: a3b4f84adafef897088c160faf7dfffb7696046cb13ae90b508c2cbc95d3b8d4
url: "https://pub.dev"
source: hosted
version: "7.0.1"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter
...@@ -75,6 +91,11 @@ packages: ...@@ -75,6 +91,11 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
leak_tracker: leak_tracker:
dependency: transitive dependency: transitive
description: description:
...@@ -139,6 +160,102 @@ packages: ...@@ -139,6 +160,102 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.9.1" version: "1.9.1"
path_provider_linux:
dependency: transitive
description:
name: path_provider_linux
sha256: f7a1fe3a634fe7734c8d3f2766ad746ae2a2884abe22e241a8b301bf5cac3279
url: "https://pub.dev"
source: hosted
version: "2.2.1"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334"
url: "https://pub.dev"
source: hosted
version: "2.1.2"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
sha256: bd6f00dbd873bfb70d0761682da2b3a2c2fccc2b9e84c495821639601d81afe7
url: "https://pub.dev"
source: hosted
version: "2.3.0"
platform:
dependency: transitive
description:
name: platform
sha256: "5d6b1b0036a5f331ebc77c850ebc8506cbc1e9416c27e59b439f917a902a4984"
url: "https://pub.dev"
source: hosted
version: "3.1.6"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
url: "https://pub.dev"
source: hosted
version: "2.1.8"
shared_preferences:
dependency: "direct main"
description:
name: shared_preferences
sha256: "6e8bf70b7fef813df4e9a36f658ac46d107db4b4cfe1048b477d4e453a8159f5"
url: "https://pub.dev"
source: hosted
version: "2.5.3"
shared_preferences_android:
dependency: transitive
description:
name: shared_preferences_android
sha256: c2c8c46297b5d6a80bed7741ec1f2759742c77d272f1a1698176ae828f8e1a18
url: "https://pub.dev"
source: hosted
version: "2.4.9"
shared_preferences_foundation:
dependency: transitive
description:
name: shared_preferences_foundation
sha256: "6a52cfcdaeac77cad8c97b539ff688ccfc458c007b4db12be584fbe5c0e49e03"
url: "https://pub.dev"
source: hosted
version: "2.5.4"
shared_preferences_linux:
dependency: transitive
description:
name: shared_preferences_linux
sha256: "580abfd40f415611503cae30adf626e6656dfb2f0cee8f465ece7b6defb40f2f"
url: "https://pub.dev"
source: hosted
version: "2.4.1"
shared_preferences_platform_interface:
dependency: transitive
description:
name: shared_preferences_platform_interface
sha256: "57cbf196c486bc2cf1f02b85784932c6094376284b3ad5779d1b1c6c6a816b80"
url: "https://pub.dev"
source: hosted
version: "2.4.1"
shared_preferences_web:
dependency: transitive
description:
name: shared_preferences_web
sha256: c49bd060261c9a3f0ff445892695d6212ff603ef3115edbb448509d407600019
url: "https://pub.dev"
source: hosted
version: "2.4.3"
shared_preferences_windows:
dependency: transitive
description:
name: shared_preferences_windows
sha256: "94ef0f72b2d71bc3e700e025db3710911bd51a71cefb65cc609dd0d9a982e3c1"
url: "https://pub.dev"
source: hosted
version: "2.4.1"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
...@@ -208,6 +325,22 @@ packages: ...@@ -208,6 +325,22 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "14.3.1" version: "14.3.1"
web:
dependency: transitive
description:
name: web
sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a"
url: "https://pub.dev"
source: hosted
version: "1.1.1"
xdg_directories:
dependency: transitive
description:
name: xdg_directories
sha256: "7a3f37b05d989967cdddcbb571f1ea834867ae2faa29725fd085180e0883aa15"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
sdks: sdks:
dart: ">=3.7.0-0 <4.0.0" dart: ">=3.7.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54" flutter: ">=3.27.0"
...@@ -34,6 +34,7 @@ dependencies: ...@@ -34,6 +34,7 @@ dependencies:
# The following adds the Cupertino Icons font to your application. # The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons. # Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.8 cupertino_icons: ^1.0.8
shared_preferences: ^2.5.3
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
......
...@@ -8,12 +8,12 @@ ...@@ -8,12 +8,12 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:peponator/main.dart'; import 'package:peponator/peponator_app.dart';
void main() { void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async { testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame. // Build our app and trigger a frame.
await tester.pumpWidget(const MyApp()); await tester.pumpWidget(const PeponatorApp());
// Verify that our counter starts at 0. // Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget); expect(find.text('0'), findsOneWidget);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment