scrabble_word_checker 0.0.3 copy "scrabble_word_checker: ^0.0.3" to clipboard
scrabble_word_checker: ^0.0.3 copied to clipboard

outdated

Check words with the official scrabble dictionary.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:scrabble_word_checker/scrabble_word_checker.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Scrabble word checker'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final ScrabbleWordChecker wordChecker = ScrabbleWordChecker();
  final GlobalKey<FormState> formKey = GlobalKey<FormState>();
  final TextEditingController controller = TextEditingController();
  String word = "";
  bool valid = false;

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  void checkWord() {
    word = "";
    valid = false;
    setState(() {});
    if (!formKey.currentState!.validate()) {
      return;
    }
    valid = wordChecker.isValidWord(controller.text.trim());
    word = controller.text.trim();
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: SafeArea(
        child: SingleChildScrollView(
          child: Padding(
            padding: const EdgeInsets.all(30.0),
            child: Column(
              children: [
                Text("Word: $word"),
                const SizedBox(height: 10.0),
                Text(
                  "Valid: ${valid.toString()}",
                ),
                const SizedBox(height: 20.0),
                Form(
                  key: formKey,
                  child: Column(
                    children: [
                      TextFormField(
                        controller: controller,
                        decoration: const InputDecoration(
                          labelText: "Enter a word",
                          hintText: "Ex: aa",
                        ),
                        validator: (value) {
                          if (value == null || value.isEmpty) {
                            return "Enter a valid word";
                          }
                          return null;
                        },
                      ),
                      const SizedBox(height: 50.0),
                      Center(
                        child: SizedBox(
                          child: ElevatedButton(
                            onPressed: checkWord,
                            child: const Text("Check"),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
3
likes
0
points
102
downloads

Publisher

verified publishertrinitynumerik.com

Weekly Downloads

Check words with the official scrabble dictionary.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on scrabble_word_checker