Skip to content
Snippets Groups Projects
Select Git revision
  • cc108a1d45ff0a11b85d31d776257cf0097fc958
  • master default protected
  • 38-upgrade-framework-and-dependencies
  • 20-improve-app-metadata
  • Release_0.8.0_32 protected
  • Release_0.7.2_31 protected
  • Release_0.7.1_30 protected
  • Release_0.7.0_29 protected
  • Release_0.6.0_28 protected
  • Release_0.5.0_27 protected
  • Release_0.4.0_26 protected
  • Release_0.3.2_25 protected
  • Release_0.3.1_24 protected
  • Release_0.3.0_23 protected
  • Release_0.2.1_22 protected
  • Release_0.2.0_21 protected
  • Release_0.1.2_20 protected
  • Release_0.1.1_19 protected
  • Release_0.1.0_18 protected
  • Release_0.0.17_17 protected
  • Release_0.0.16_16 protected
  • Release_0.0.15_15 protected
  • Release_0.0.14_14 protected
  • Release_0.0.13_13 protected
24 results

styled_button.dart

Blame
  • global_app_bar.dart 2.84 KiB
    import 'package:flutter/material.dart';
    import 'package:flutter_bloc/flutter_bloc.dart';
    
    import 'package:petitbac/config/menu.dart';
    import 'package:petitbac/cubit/game_cubit.dart';
    import 'package:petitbac/cubit/nav_cubit.dart';
    import 'package:petitbac/models/game/game.dart';
    import 'package:petitbac/ui/helpers/app_titles.dart';
    import 'package:petitbac/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,
                    ));
                  }