0

I'm having this error showing "another exception was thrown Incorrect use of ParentDataWidget" when I press my Elevated button and I don't have any more details into the console so I have no idea how to fix this. Also the others buttons don't do anything at all when I try to click on them (not even print "hello"). Can someone help please :)

final colorProvider = StateProvider((ref) {
  return {"us": splashBackground, "fr": splashBackground};
});

void main() {
  runApp(const ProviderScope(child: WorldMap()));
}

class WorldMap extends ConsumerStatefulWidget {
  const WorldMap({super.key});

  @override
  ConsumerState<WorldMap> createState() => _WorldMapState();
}

class _WorldMapState extends ConsumerState<WorldMap>
    with TickerProviderStateMixin {
  late TimerController _timerController;
  Map country = {...countries_info};
  Map<String, Color> previousColoring = {};
  late var guess;

  bool textField = true;
  bool showWidget = false;

  final List<String> _countryName = [];
  TextEditingController textarea = TextEditingController();

  @override
  void initState() {
    _timerController = TimerController(this);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: blueMap,
        body: Padding(
          padding: const EdgeInsets.all(15.0),
          child: Column(
            children: [
              TextField(
                enabled: textField,
                style: const TextStyle(color: splashBackground),
                textInputAction: TextInputAction.none,
                textAlign: TextAlign.center,
                controller: textarea,
                decoration: InputDecoration(
                  hintStyle: const TextStyle(color: splashBackground),
                  filled: true,
                  fillColor: purpleList,
                  border: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(30),
                    borderSide:
                        const BorderSide(color: splashBackground, width: 2),
                  ),
                  hintText: "Enter the name of a country",
                ),
                onSubmitted: (String userInput) {
                  guess = userInput.toLowerCase();
                  if (country.containsKey(guess)) {
                    setState(() {
                      _countryName.add(guess);

                      ref
                          .read(colorProvider.notifier)
                          .state
                          .forEach((key, value) {
                        previousColoring[key] = value;
                      });

                      previousColoring[country[guess]!['code']!.toLowerCase()] =
                          backgroundHighlight;
                      ref.read(colorProvider.notifier).state = previousColoring;
                    });
                    country.remove(guess);
                    _timerController.add(const Duration(seconds: 5));
                    _timerController.start();
                  } else if (!countries_info.containsKey(guess) &&
                      !_countryName.contains(guess)) {
                    _timerController.subtract(const Duration(seconds: 5));
                    _timerController.start();
                  }
                  textarea.clear();
                },
              ),
              const SizedBox(height: 35),
              ElevatedButton(
                child: const Text("Start"),
                onPressed: () {
                  _timerController.start();
                },
              ),
              const SizedBox(height: 35),
              Column(
                children: [
                  Container(
                    width: 50,
                    height: 50,
                    child: SimpleTimer(
                      timerStyle: TimerStyle.expanding_sector,
                      backgroundColor: splashBackground,
                      progressIndicatorColor: backgroundHighlight,
                      controller: _timerController,
                      duration: const Duration(seconds: 20),
                      onEnd: () {
                        setState(() {
                          textField = false;
                          // show page with country guessed and country missing?
                        });
                      },
                    ),
                  ),
                  Text("Your score is : ${_countryName.length}")
                ],
              ),
              const SizedBox(height: 35),
              Container(
                height: 100,
                child: InteractiveViewer(
                  minScale: 1,
                  maxScale: 10,
                  child: MySimpleDynamicMap(
                    coloring: ref.watch(colorProvider),
                  ),
                ),
              ),
              Container(
                height: 100,
                child: Expanded(
                  child: ListView.builder(
                    itemCount: _countryName.length,
                    itemBuilder: (BuildContext ctxt, int index) {
                      return Text(
                        _countryName[index],
                        style: const TextStyle(color: splashBackground),
                      );
                    },
                  ),
                ),
              ),
              const SizedBox(height: 35),

//When pressing elevated button below and other buttons don't do anything
              ElevatedButton(
                onPressed: () {
                  setState(() {
                    showWidget = !showWidget;
                  });
                },
                child: const Icon(Icons.question_mark_rounded),
              ),
              const SizedBox(height: 35),
              showWidget
                  ? Clues(
                      colorCountryleft: () {
                        for (var element in country.keys) {
                        }
                      },
                    )
                  : const SizedBox(),
              Text(
                "${_countryName.length}/${countries_info.length}",
                style: const TextStyle(color: splashBackground),
              ),
              ProgessBar(
                totalCounrty: countries_info.length,
                guessedCountry: _countryName.length,
              )
            ],
          ),
        ),
      ),
    );
  }
}

class MySimpleDynamicMap extends StatelessWidget {
  final Map<String, dynamic> coloring;

  const MySimpleDynamicMap({Key? key, required this.coloring})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SimpleMap(
      // String of instructions to draw the map.
      instructions: SMapWorld.instructions,

      // Default color for all countries.
      defaultColor: splashBackground,

      // Matching class to specify custom colors for each area.
      colors: coloring,
    );
  }
}

class ProgessBar extends StatelessWidget {
  final int totalCounrty;
  final int guessedCountry;
  const ProgessBar(
      {super.key, required this.totalCounrty, required this.guessedCountry});

  @override
  Widget build(BuildContext context) {
    return StepProgressIndicator(
      totalSteps: totalCounrty,
      currentStep: guessedCountry,
      size: 20,
      padding: 0,
      selectedColor: backgroundHighlight,
      unselectedColor: splashBackground,
      roundedEdges: const Radius.circular(10),
    );
  }
}

class Clues extends StatelessWidget {
  Clues({super.key, required colorCountryleft});
  Function colorCountryLeft = () {};

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        ElevatedButton(
          onPressed: () {
            colorCountryLeft();
            //Light all country not guessed on the map
          },
          child: const Text("Use clue bleh bleh bleh"),
        ),
        const SizedBox(height: 35),
        ElevatedButton(
          onPressed: () {
            // show map of a random not guessed country?
          },
          child: const Text("Use clue bleh bleh bleh"),
        ),
      ],
    );
  }
}
Coca95
  • 31
  • 5

0 Answers0