Skip to content
Snippets Groups Projects
Select Git revision
  • 60b0bef8ca1a7453167564b1e734412a04c9668f
  • master default protected
  • 61-upgrade-framework-and-dependencies
  • 42-improve-app-metadata
  • 17-improve-and-complete-offline-words-list-and-tips
  • 6-allow-translate-application
  • 9-improve-documentation
  • Release_1.10.0_44 protected
  • Release_1.9.2_43 protected
  • Release_1.9.1_42 protected
  • Release_1.9.0_41 protected
  • Release_1.8.0_40 protected
  • Release_1.7.0_39 protected
  • Release_1.6.0_38 protected
  • Release_1.5.2_37 protected
  • Release_1.5.1_36 protected
  • Release_1.5.0_35 protected
  • Release_1.4.1_34 protected
  • Release_1.4.0_33 protected
  • Release_1.3.2_32 protected
  • Release_1.3.1_31 protected
  • Release_1.3.0_30 protected
  • Release_1.2.18_29 protected
  • Release_1.2.17_28 protected
  • Release_1.2.16_27 protected
  • Release_1.2.15_26 protected
  • Release_1.2.14_25 protected
27 results

letters.dart

Blame
  • letters.dart 3.10 KiB
    import 'package:flutter/material.dart';
    import 'package:provider/provider.dart';
    import '../provider/data.dart';
    import '../utils/constants.dart';
    import '../widgets/dialog_gameover.dart';
    
    class LetterButtons extends StatelessWidget {
      const LetterButtons({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        Orientation orientation = MediaQuery.of(context).orientation;
        var size = MediaQuery.of(context).size;
        final double paddingTop = MediaQuery.of(context).padding.top;
        final double itemHeight = (size.height - paddingTop) / 2;
        final double itemWidth = size.width / 2;
    
        Data _myProvider = Provider.of<Data>(context);
    
        List<String> lettersList = letters.split('');
        List<Widget> keys = [];
        lettersList.forEach((key) {
          keys.add(
            Padding(
              padding: const EdgeInsets.all(2.0),
              child: ElevatedButton(
                style: ElevatedButton.styleFrom(
                  primary: Colors.grey,
                  onPrimary: Colors.white,
                  shadowColor: Color(accent),
                ),
                onPressed: _myProvider.usedLetters.contains(key)
                    ? null
                    : () async {
                        _myProvider.updateUsedLetters(key);
                        if (_myProvider.secretWord.contains(key)) {
                          for (int index = 0; index < _myProvider.secretWord.length; index++) {
                            if (key == _myProvider.secretWord[index]) {
                              _myProvider.updateHiddenWord(index, key);
                            }
                          }
    
                          if (_myProvider.hiddenWord == _myProvider.secretWord) {
                            _myProvider.addVictory();
                            showDialog(
                              context: context,
                              builder: (context) => DialogGameOver(victory),
                            );
                          }
                        } else {
                          _myProvider.addError();
                          if (_myProvider.errors == 8) {
                            await Future.delayed(Duration(milliseconds: 900)); //????
                            _myProvider.addDefeat();
                            showDialog(
                              context: context,
                              builder: (context) => DialogGameOver(defeat),
                            );
                          }
                        }
                      },
                child: Text(
                  key,
                  textAlign: TextAlign.center,
                ),
              ),
            ),
          );
        });
        return Container(
          alignment:
              orientation == Orientation.portrait ? Alignment.bottomCenter : Alignment.center,
          color: Color(darkGreen),
          padding: EdgeInsets.all(10.0),
          margin: EdgeInsets.only(top: orientation == Orientation.portrait ? 0.0 : paddingTop),
          child: GridView.count(
            padding: EdgeInsets.zero,
            shrinkWrap: true,
            crossAxisCount: orientation == Orientation.portrait ? 9 : 3,
            childAspectRatio:
                orientation == Orientation.portrait ? 1 / 1 : (itemWidth / itemHeight),
            children: keys,
          ),
        );
      }
    }