mirrored_repositories/flutter_apps/dicee
import 'dart:math';
import 'package:flutter/material.dart';

void main() {
  runApp(const DiceApp());
}

class DiceApp extends StatelessWidget {
  const DiceApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Colors.red,
        appBar: _appBar(),
        body: const DicePage(),
      ),
    );
  }

  AppBar _appBar() {
    return AppBar(
      title: const Center(child: Text('Dicee')),
      backgroundColor: Colors.red,
    );
  }
}

class DicePage extends StatefulWidget {
  const DicePage({Key? key}) : super(key: key);

  @override
  State<DicePage> createState() => _DicePageState();
}

class _DicePageState extends State<DicePage> {
  int _leftDiceNumber = Random().nextInt(6) + 1;
  int _rightDiceNumber = Random().nextInt(6) + 1;

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Row(
        children: <Widget>[
          Expanded(
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: TextButton(
                child: Image.asset('images/dice$_leftDiceNumber.png'),
                onPressed: () {
                  _rollDice();
                },
              ),
            ),
          ),
          Expanded(
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: TextButton(
                child: Image.asset('images/dice$_rightDiceNumber.png'),
                onPressed: () {
                  _rollDice();
                },
              ),
            ),
          ),
        ],
      ),
    );
  }

  void _rollDice() {
    setState(() {
      _leftDiceNumber = Random().nextInt(6) + 1;
      _rightDiceNumber = Random().nextInt(6) + 1;
    });
  }
}
