Skip to content
Snippets Groups Projects
Select Git revision
  • 11a39266fe7c7328922362fa839905c66cc97fb3
  • master default protected
  • 47-upgrade-framework-and-dependencies
  • 27-improve-app-metadata
  • 6-fix-display-grid
  • Release_1.9.0_38 protected
  • Release_1.8.2_37 protected
  • Release_1.8.1_36 protected
  • Release_1.8.0_35 protected
  • Release_1.7.0_34 protected
  • Release_1.6.0_33 protected
  • Release_1.5.0_32 protected
  • Release_1.4.3_31 protected
  • Release_1.4.2_30 protected
  • Release_1.4.1_29 protected
  • Release_1.4.0_28 protected
  • Release_1.3.1_27 protected
  • Release_1.3.0_26 protected
  • Release_1.2.1_25 protected
  • Release_1.2.0_24 protected
  • Release_1.1.0_23 protected
  • Release_1.0.21_22 protected
  • Release_1.0.20_21 protected
  • Release_1.0.19_20 protected
  • Release_1.0.18_19 protected
25 results

application_config.dart

Blame
  • global_app_bar.dart 2.83 KiB
    import 'package:flutter/material.dart';
    import 'package:flutter_bloc/flutter_bloc.dart';
    
    import 'package:reversi/config/menu.dart';
    import 'package:reversi/cubit/game_cubit.dart';
    import 'package:reversi/cubit/nav_cubit.dart';
    import 'package:reversi/models/game/game.dart';
    import 'package:reversi/ui/helpers/app_titles.dart';
    import 'package:reversi/ui/helpers/styled_button.dart';
    
    class GlobalAppBar extends StatelessWidget implements PreferredSizeWidget {
      const GlobalAppBar({super.key});
    
      @override
      Widget build(BuildContext context) {
        return BlocBuilder<GameCubit, GameState>(
          builder: (BuildContext context, GameState gameState) {
            return BlocBuilder<NavCubit, int>(
              builder: (BuildContext context, int pageIndex) {
                final Game currentGame = gameState.currentGame;
    
                final List<Widget> menuActions = [];
    
                if (currentGame.isRunning && !currentGame.isFinished) {
                  menuActions.add(StyledButton(
                    color: Colors.red,
                    onPressed: () {},
                    onLongPress: () {
                      BlocProvider.of<GameCubit>(context).quitGame();
                    },
                    child: const Image(
                      image: AssetImage('assets/ui/button_back.png'),
                      fit: BoxFit.fill,
                    ),
                  ));
                } else {
                  if (pageIndex == Menu.indexGame) {
                    // go to Settings page
                    menuActions.add(ElevatedButton(
                      onPressed: () {
                        context.read<NavCubit>().goToSettingsPage();
                      },
                      style: ElevatedButton.styleFrom(
                        shape: const CircleBorder(),
                      ),
                      child: Menu.menuItemSettings.icon,
                    ));
    
                    // go to About page
                    menuActions.add(ElevatedButton(
                      onPressed: () {
                        context.read<NavCubit>().goToAboutPage();
                      },
                      style: ElevatedButton.styleFrom(
                        shape: const CircleBorder(),
                      ),
                      child: Menu.menuItemAbout.icon,
                    ));
                  } else {
                    // back to Home page
                    menuActions.add(ElevatedButton(
                      onPressed: () {
                        context.read<NavCubit>().goToGamePage();
                      },
                      style: ElevatedButton.styleFrom(
                        shape: const CircleBorder(),
                      ),
                      child: Menu.menuItemGame.icon,
                    ));
                  }