Skip to content

Commit

Permalink
Keyboard keys disable feature
Browse files Browse the repository at this point in the history
  • Loading branch information
samitkapoor committed Jun 20, 2022
1 parent f9adb61 commit 2451103
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 29 deletions.
47 changes: 25 additions & 22 deletions lib/components/keyboard_row.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'package:wordle/components/my_key.dart';
import 'package:wordle/controllers/action.dart';
Expand All @@ -17,27 +18,29 @@ class MyKeyboardRow extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Container(
height: 50,
padding: const EdgeInsets.symmetric(vertical: 5),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
...row.map(
(alphabet) {
return InkWell(
borderRadius: BorderRadius.circular(5),
onTap: () {
actionController.onKeyPress(alphabet.value);
},
child: MyKey(
alphabet: alphabet,
),
);
},
).toList(),
],
),
);
return GetBuilder<ActionController>(builder: (controller) {
return Container(
height: 50,
padding: const EdgeInsets.symmetric(vertical: 5),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
...row.map(
(alphabet) {
return InkWell(
borderRadius: BorderRadius.circular(5),
onTap: () {
controller.onKeyPress(alphabet.value);
},
child: MyKey(
alphabet: alphabet,
),
);
},
).toList(),
],
),
);
});
}
}
9 changes: 8 additions & 1 deletion lib/components/my_key.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:google_fonts/google_fonts.dart';

import 'package:wordle/controllers/action.dart';
import 'package:wordle/models/alphabet.dart';

//A row in a keyboard contains some alphabets
Expand All @@ -17,6 +19,8 @@ class MyKey extends StatelessWidget {
//This variable contains the information about the key that we are currently rendering
Alphabet alphabet;

ActionController actionController = Get.find<ActionController>();

@override
Widget build(BuildContext context) {
return Container(
Expand All @@ -25,7 +29,10 @@ class MyKey extends StatelessWidget {
width: (MediaQuery.of(context).size.width - 10 - 40) / 10,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: alphabet.disabled ? Colors.grey : Theme.of(context).primaryColor,
color:
actionController.keyboard.disabledAlphabets.contains(alphabet.value)
? Colors.grey
: Theme.of(context).primaryColor,
),
alignment: Alignment.center,
child: Text(
Expand Down
1 change: 0 additions & 1 deletion lib/constants/words.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15445,7 +15445,6 @@ const List<String> words = [
'weave',
'webby',
'weber',
'wecht',
'wedel',
'wedge',
'wedgy',
Expand Down
4 changes: 3 additions & 1 deletion lib/controllers/action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ class ActionController extends GetxController {
wordSlot.wordSlots[inputNumber]['slots'][i].color = Colors.green;
} else if (findInString(wordToWin, input[i])) {
wordSlot.wordSlots[inputNumber]['slots'][i].color = Colors.orange;
} else {}
} else {
keyboard.disabledAlphabets.add(input[i]);
}
}

//if the word input by the user is the word that we are guessing, then he won
Expand Down
3 changes: 3 additions & 0 deletions lib/data/keyboard.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'package:wordle/models/alphabet.dart';

class Keyboard {
//All the disabled alphabets will be stored inside this list
List<String> disabledAlphabets = [];

//List containing all the alphabets in the top row of the keyboard
List<Alphabet> rowOne = [
Alphabet(value: 'q', position: 0),
Expand Down
5 changes: 1 addition & 4 deletions lib/models/alphabet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@ class Alphabet {
//on which position is the alphabet placed inside the word
int position;

bool disabled;

Alphabet(
{required this.value, required this.position, this.disabled = false});
Alphabet({required this.value, required this.position});
}

0 comments on commit 2451103

Please sign in to comment.