Created with <3 with dartpad.dev.
Last active
January 29, 2024 19:26
-
-
Save hardy716/f17008c9f9fa79ea051c6c30fbff8921 to your computer and use it in GitHub Desktop.
플러터챌린지 6일차 기본문제 - 신현호
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math'; | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: HelloDialogScreen(), | |
)); | |
} | |
class HelloDialogScreen extends StatefulWidget { | |
const HelloDialogScreen({super.key}); | |
@override | |
State<HelloDialogScreen> createState() => _HelloDialogScreenState(); | |
} | |
class _HelloDialogScreenState extends State<HelloDialogScreen> { | |
String point = '0'; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
Text( | |
"Your point : $point", | |
style: Theme.of(context).textTheme.titleLarge, | |
), | |
const SizedBox(height: 25), | |
ElevatedButton( | |
onPressed: () async { | |
await showDialog( | |
context: context, | |
builder: (context) { | |
return AlertDialog( | |
title: const Text("Choose your next point!"), | |
content: const Text("Choose one of the points below!\nIf you don't make a selection, your current score will be retained."), | |
actions: List.generate(3, (index) { | |
String number = Random().nextInt(100).toString(); | |
return TextButton( | |
onPressed: () { | |
setState(() { | |
point = number; | |
}); | |
Navigator.pop(context); | |
}, | |
child: Text(number), | |
); | |
}), | |
); | |
}, | |
); | |
}, | |
child: const Text("I want more points!"), | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment