Skip to content

Commit

Permalink
fix bits routing
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrir committed Oct 27, 2024
1 parent b336381 commit 043e2b6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/pages/games/bits/bits_home_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:online/components/separator.dart';
import 'package:online/pages/games/bits/bits_page.dart';
import '../../../components/animated_button.dart';
Expand Down Expand Up @@ -128,15 +129,16 @@ class BitsHomePageState extends State<BitsHomePage> {
return filledFields >= 2;
}

void _startGame() {
void _startGame(BuildContext context) {
bool anyFieldEmpty = controllers.any((controller) => controller.text.trim().isEmpty);

if (anyFieldEmpty) {
return showErrorTop("Deltakerfeltene må være fylt ut");
}

List<String> playerNames = controllers.map((c) => c.text.trim()).toList();
AppNavigator.navigateToPage(BitsGame(playerNames: playerNames), withHeaderNavbar: false);

context.go('/social/games/bitsgame', extra: playerNames);
}

@override
Expand Down Expand Up @@ -226,7 +228,7 @@ class BitsHomePageState extends State<BitsHomePage> {
Expanded(
child: AnimatedButton(
onTap: () async {
_startGame();
_startGame(context);
},
childBuilder: (context, hover, pointerDown) {
return Padding(
Expand Down
8 changes: 8 additions & 0 deletions lib/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:go_router/go_router.dart';
import 'package:online/pages/games/bits/bits_page.dart';
import 'package:url_launcher/url_launcher.dart';

import '/pages/games/bits/bits_home_page.dart';
Expand Down Expand Up @@ -307,6 +308,13 @@ final GoRouter router = GoRouter(
return BitsHomePage();
},
),
GoRoute(
path: 'bitsgame',
builder: (context, state) {
final playerNames = state.extra as List<String>? ?? [];
return BitsGame(playerNames: playerNames);
},
),
],
),
],
Expand Down

0 comments on commit 043e2b6

Please sign in to comment.