Skip to content
Snippets Groups Projects
Select Git revision
  • bf8bd0496ea2b5188b9baff06cdaa7496047ae97
  • master default protected
  • 31-upgrade-framework-and-dependencies
  • 12-improve-ai
  • 14-improve-app-metadata
  • Release_0.8.0_25 protected
  • Release_0.7.2_24 protected
  • Release_0.7.1_23 protected
  • Release_0.7.0_22 protected
  • Release_0.6.0_21 protected
  • Release_0.5.0_20 protected
  • Release_0.4.0_19 protected
  • Release_0.3.2_18 protected
  • Release_0.3.1_17 protected
  • Release_0.3.0_16 protected
  • Release_0.2.1_15 protected
  • Release_0.2.0_14 protected
  • Release_0.1.1_13 protected
  • Release_0.1.0_12 protected
  • Release_0.0.11_11 protected
  • Release_0.0.10_10 protected
  • Release_0.0.9_9 protected
  • Release_0.0.8_8 protected
  • Release_0.0.7_7 protected
  • Release_0.0.6_6 protected
25 results

game_layout.dart

Blame
  • game.dart 4.63 KiB
    import 'package:flutter/material.dart';
    import 'package:provider/provider.dart';
    
    import '../provider/data.dart';
    import '../utils/constants.dart';
    import '../utils/random_pick.dart';
    import '../widgets/letters.dart';
    
    class Game extends StatelessWidget {
      const Game({super.key});
    
      static const String id = 'game';
    
      Future<void> pickWord(BuildContext context, Data myProvider) async {
        myProvider.searching = true;
        RandomPick randompick;
        int attempts = 0;
        do {
          randompick = RandomPick(myProvider.levelPref);
          await randompick.init();
          if (randompick.word != '') {
            myProvider.updateSecretWord = randompick.word;
            myProvider.resetSuccessAndErrors();
            myProvider.resetUsedLetters();
            if (myProvider.levelPref == defaultLevel) {
              myProvider.updateClue = randompick.clue;
            }
            myProvider.searching = false;
            break;
          }
          attempts++;
        } while (attempts < 3);
      }
    
      @override
      Widget build(BuildContext context) {
        Orientation orientation = MediaQuery.of(context).orientation;
        Data myProvider = Provider.of<Data>(context);
    
        return Scaffold(
          backgroundColor: const Color(board),
          floatingActionButton: myProvider.levelPref == defaultLevel
              ? FloatingActionButton(
                  foregroundColor: Colors.white,
                  backgroundColor: Colors.transparent,
                  elevation: 0.0,
                  onPressed: () {
                    showDialog(
                      context: context,
                      builder: (context) {
                        return AlertDialog(
                          title: const Text('Indice'),
                          content: Text(myProvider.clue),
                          actions: <Widget>[
                            TextButton(
                              child: const Text('Revenir au jeu'),
                              onPressed: () => Navigator.of(context).pop(),
                            )
                          ],
                        );
                      },
                    );
                  },
                  child: const Icon(Icons.help_outline),
                )
              : null,
          floatingActionButtonLocation: orientation == Orientation.portrait
              ? FloatingActionButtonLocation.endTop
              : FloatingActionButtonLocation.centerTop,
          body: orientation == Orientation.portrait
              ? const Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Flexible(
                      child: Padding(
                        padding: EdgeInsets.only(top: 60.0, left: 30.0, right: 30.0, bottom: 10.0),
                        child: ImgGallow(),
                      ),
                    ),
                    Padding(
                      padding: EdgeInsets.symmetric(horizontal: 30.0),
                      child: HiddenWord(),
                    ),
                    LetterButtons(),
                  ],
                )
              : const Row(
                  children: [
                    Expanded(
                      flex: 2,
                      child: Column(
                        children: [
                          Expanded(
                            child: Padding(
                              padding: EdgeInsets.only(top: 40.0),
                              child: ImgGallow(),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.symmetric(horizontal: 10.0, vertical: 20.0),
                            child: HiddenWord(),
                          ),
                        ],
                      ),
                    ),
                    Expanded(child: LetterButtons()),
                  ],
                ),
        );
      }
    }
    
    class ImgGallow extends StatelessWidget {
      const ImgGallow({super.key});
      @override
      Widget build(BuildContext context) {
        Data myProvider = Provider.of<Data>(context);
        return Stack(
          children: [
            for (int error = 0; error < 9; error++)
              AnimatedOpacity(
                opacity: myProvider.errors >= error ? 1.0 : 0.0,
                duration: Duration(milliseconds: myProvider.errors >= error ? 800 : 0),
                child: Image.asset('assets/images/img${error + 1}.png'),
              )
          ],
        );
      }
    }
    
    class HiddenWord extends StatelessWidget {
      const HiddenWord({super.key});
      @override
      Widget build(BuildContext context) {
        Data myProvider = Provider.of<Data>(context);
        return FittedBox(
          child: Text(
            (myProvider.hiddenWord.isEmpty || myProvider.hiddenWord == '')
                ? 'UNEXPECTED ERROR'
                : myProvider.hiddenWord,
            style: const TextStyle(
              fontFamily: 'Tiza',
              color: Colors.white,
              fontSize: 34.0,
              letterSpacing: 10.0,
            ),
          ),
        );
      }
    }