import 'package:flutter/material.dart'; import 'dart:math'; void main() { runApp(const DiceControllerApp()); } class DiceControllerApp extends StatelessWidget { const DiceControllerApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Zupee Dice Controller', debugShowCheckedModeBanner: false, theme: ThemeData.dark().copyWith( scaffoldBackgroundColor: const Color(0xFF0f0f0f), ), home: const DiceControllerScreen(), ); } } class DiceControllerScreen extends StatefulWidget { const DiceControllerScreen({super.key}); @override State createState() => _DiceControllerScreenState(); } class _DiceControllerScreenState extends State { int _diceValue = 0; final TextEditingController _inputController = TextEditingController(); final List _diceEmojis = ["", "⚀", "⚁", "⚂", "⚃", "⚄", "⚅"]; void _rollDice() { setState(() { _diceValue = Random().nextInt(6) + 1; }); } void _setDice() { if (_inputController.text.isEmpty) { _showAlert("Please enter a value"); return; } final value = int.tryParse(_inputController.text); if (value == null || value < 1 || value > 6) { _showAlert("Please enter a value between 1 and 6"); return; } setState(() { _diceValue = value; }); } void _showAlert(String message) { showDialog( context: context, builder: (context) => AlertDialog( backgroundColor: const Color(0xFF1a1a1a), title: const Text("Invalid Input", style: TextStyle(color: Colors.white)), content: Text(message, style: const TextStyle(color: Colors.white70)), actions: [ TextButton( onPressed: () => Navigator.pop(context), child: const Text("OK", style: TextStyle(color: Color(0xFFffcc00))), ) ], ), ); } @override Widget build(BuildContext context) { return Scaffold( body: Center( child: Container( constraints: const BoxConstraints(maxWidth: 400), padding: const EdgeInsets.all(30), child: Card( elevation: 8, color: const Color(0xFF1a1a1a), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(20), ), child: Padding( padding: const EdgeInsets.all(30), child: Column( mainAxisSize: MainAxisSize.min, children: [ const Text( "Zupee Dice Controller", style: TextStyle( fontSize: 24, fontWeight: FontWeight.bold, color: Colors.white, ), ), const SizedBox(height: 20), Container( padding: const EdgeInsets.symmetric(vertical: 20), child: Text( _diceValue == 0 ? "🎲" : _diceEmojis[_diceValue], style: const TextStyle(fontSize: 100), ), ), const SizedBox(height: 10), ElevatedButton( onPressed: _rollDice, style: ElevatedButton.styleFrom( backgroundColor: const Color(0xFFffcc00), foregroundColor: Colors.black, padding: const EdgeInsets.symmetric( horizontal: 30, vertical: 15, ), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), ), ), child: const Text( "Roll", style: TextStyle(fontSize: 18), ), ), const SizedBox(height: 20), const Text( "Set Dice Value (1–6):", style: TextStyle( fontSize: 16, color: Colors.white70, ), ), const SizedBox(height: 10), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ SizedBox( width: 80, child: TextField( controller: _inputController, keyboardType: TextInputType.number, textAlign: TextAlign.center, style: const TextStyle(fontSize: 18, color: Colors.white), decoration: InputDecoration( filled: true, fillColor: Colors.grey[900], border: OutlineInputBorder( borderRadius: BorderRadius.circular(10), borderSide: BorderSide.none, ), contentPadding: const EdgeInsets.symmetric( vertical: 10, horizontal: 15, ), ), ), ), const SizedBox(width: 15), ElevatedButton( onPressed: _setDice, style: ElevatedButton.styleFrom( backgroundColor: const Color(0xFFffcc00), foregroundColor: Colors.black, padding: const EdgeInsets.symmetric( horizontal: 20, vertical: 12, ), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), ), ), child: const Text( "Set", style: TextStyle(fontSize: 18), ), ), ], ), ], ), ), ), ), ), ); } }

Comments