ソースコード source code

下記アプリの主要なソースコードを公開しています。アプリ開発の参考になれば幸いです。

画像等が別途必要ですので下記情報のみでアプリが完成するものではありません。 アプリは少しずつ機能拡張していますのでストア公開されているアプリと内容が異なる場合があります。 コードはコピーして自由にお使いいただけます。ただし著作権は放棄しておりませんので全部の再掲載はご遠慮ください。部分的に再掲載したり、改変して再掲載するのは構いません。 自身のアプリ作成の参考として個人使用・商用問わず自由にお使いいただけます。 コード記述のお手本を示すものではありません。ミニアプリですので変数名などさほど気遣いしていない部分も有りますし間違いも有るかと思いますので参考程度にお考え下さい。 他の賢者の皆様が公開されているコードを参考にした箇所も含まれます。Flutter開発の熟練者が書いたコードではありません。 エンジニア向け技術情報共有サービスではありませんので説明は省いています。 GitHubなどへの公開は予定しておりません。

下記コードの最終ビルド日: 2022-12-06

pubspec.yaml

name: cardscalculation
description: Cards Calculation

# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.2+3

environment:
  sdk: ">=2.18.5 <3.0.0"

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
  flutter:
    sdk: flutter
  shared_preferences: ^2.0.15
  just_audio: ^0.9.30
  flutter_svg: ^1.1.6
  google_mobile_ads: ^2.3.0
  flutter_localizations:    #多言語ライブラリの本体    # .arbファイルを更新したら flutter gen-l10n
    sdk: flutter
  intl: ^0.17.0   #多言語やフォーマッタなどの関連ライブラリ
  package_info_plus: ^3.0.2


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.5

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_launcher_icons: ^0.11.0    #flutter pub run flutter_launcher_icons
  flutter_native_splash: ^2.2.15     #flutter pub run flutter_native_splash:create

  # The "flutter_lints" package below contains a set of recommended lints to
  # encourage good coding practices. The lint set provided by the package is
  # activated in the `analysis_options.yaml` file located at the root of your
  # package. See that file for information about deactivating specific lint
  # rules and activating additional ones.
  flutter_lints: ^2.0.1

flutter_icons:
  android: "launcher_icon"
  ios: true
  image_path: "assets/icon/icon.png"
  adaptive_icon_background: "assets/icon/icon_back.png"
  adaptive_icon_foreground: "assets/icon/icon_fore.png"

flutter_native_splash:
  color: '#26f19a'
  image: 'assets/image/splash.png'
  color_dark: '#26f19a'
  image_dark: 'assets/image/splash.png'
  fullscreen: true
  android_12:
    icon_background_color: '#26f19a'
    image: 'assets/image/splash.png'
    icon_background_color_dark: '#26f19a'
    image_dark: 'assets/image/splash.png'


# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter packages.
flutter:
  assets:
    - assets/sound/
    - assets/icon/
    - assets/image/
  generate: true    #自動生成フラグの有効化

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  # assets:
  #   - images/a_dot_burr.jpeg
  #   - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

lib/ad_mob.dart

///
/// @author akira ohmachi
/// @copyright ao-system, Inc.
/// @date 2022-12-06
///

import 'package:flutter/material.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'dart:io';

class AdMob {
  late BannerAd _adMobBanner;
  bool _isAdMob = false;
  AdMob() { //constructor
    String adBannerUnitId = '';
    if (!kIsWeb && Platform.isAndroid) {
      adBannerUnitId = 'ca-app-pub-0000000000000000/0000000000';
      _isAdMob = true;
    } else if (!kIsWeb && Platform.isIOS) {
      adBannerUnitId = 'ca-app-pub-0000000000000000/0000000000';
      _isAdMob = true;
    }
    if (_isAdMob) {
      _adMobBanner = BannerAd(
        adUnitId: adBannerUnitId,
        size: AdSize.banner,
        request: const AdRequest(),
        listener: const BannerAdListener(),
      );
    }
  }
  void load() {
    if (_isAdMob) {
      _adMobBanner.load();
    }
  }
  Widget getAdBannerWidget() {
    if (_isAdMob) {
      return Container(
        alignment: Alignment.center,
        width: _adMobBanner.size.width.toDouble(),
        height: _adMobBanner.size.height.toDouble(),
        child: AdWidget(ad: _adMobBanner),
      );
    } else {
      return Container(height: 150);
    }
  }
  double getAdBannerHeight() {
    if (_isAdMob) {
      return _adMobBanner.size.height.toDouble();
    } else {
      return 150;  //for web
    }
  }
}

lib/app_condition.dart

///
/// @author akira ohmachi
/// @copyright ao-system, Inc.
/// @date 2022-11-26
///

class AppCondition {
  String appVersion = '';
  double canvasWidth = 0;
  //
  String getAppVersion() {
    return appVersion;
  }
  void setAppVersion(String str) {
    appVersion = str;
  }
  double getCanvasWidth() {
    return canvasWidth;
  }
  void setCanvasWidth(double w) {
    canvasWidth = w;
  }
}

lib/audio_play.dart

///
/// @author akira ohmachi
/// @copyright ao-system, Inc.
/// @date 2022-11-26
///

import 'package:just_audio/just_audio.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:cardscalculation/const_value.dart';

class AudioPlay {
  static const int soundOff = 1;
  static const int soundOn = 2;
  final String _audioStart = ConstValue.soundStart;
  final String _audioRetry = ConstValue.soundRetry;
  final String _audioBack = ConstValue.soundBack;
  final String _audioSlide = ConstValue.soundSlide;
  final String _audioComplete = ConstValue.soundComplete;
  static final List<AudioPlayer> _audioPlayerStart = [
    AudioPlayer(),
    AudioPlayer(),
    AudioPlayer(),
  ];
  static final List<AudioPlayer> _audioPlayerRetry = [
    AudioPlayer(),
    AudioPlayer(),
    AudioPlayer(),
  ];
  static final List<AudioPlayer> _audioPlayerBack = [
    AudioPlayer(),
    AudioPlayer(),
    AudioPlayer(),
    AudioPlayer(),
    AudioPlayer(),
    AudioPlayer(),
    AudioPlayer(),
    AudioPlayer(),
    AudioPlayer(),
    AudioPlayer(),
  ];
  static final List<AudioPlayer> _audioPlayerSlide = [
    AudioPlayer(),
    AudioPlayer(),
    AudioPlayer(),
    AudioPlayer(),
    AudioPlayer(),
    AudioPlayer(),
    AudioPlayer(),
    AudioPlayer(),
    AudioPlayer(),
    AudioPlayer(),
  ];
  static final List<AudioPlayer> _audioPlayerComplete = [
    AudioPlayer(),
    AudioPlayer(),
    AudioPlayer(),
  ];
  int _sound = soundOn;
  int _audioPlayerStartPtr = 0;
  int _audioPlayerRetryPtr = 0;
  int _audioPlayerBackPtr = 0;
  int _audioPlayerSlidePtr = 0;
  int _audioPlayerCompletePtr = 0;
  AudioPlay() { //constructor
    init();
  }
  void init() async {
    for (int i = 0; i < _audioPlayerStart.length; i++) {
      await _audioPlayerStart[i].setAsset(_audioStart);
    }
    for (int i = 0; i < _audioPlayerRetry.length; i++) {
      await _audioPlayerRetry[i].setAsset(_audioRetry);
    }
    for (int i = 0; i < _audioPlayerBack.length; i++) {
      await _audioPlayerBack[i].setAsset(_audioBack);
    }
    for (int i = 0; i < _audioPlayerSlide.length; i++) {
      await _audioPlayerSlide[i].setAsset(_audioSlide);
    }
    for (int i = 0; i < _audioPlayerComplete.length; i++) {
      await _audioPlayerComplete[i].setAsset(_audioComplete);
    }
  }
  void dispose() {
    for (int i = 0; i < _audioPlayerStart.length; i++) {
      _audioPlayerStart[i].dispose();
    }
    for (int i = 0; i < _audioPlayerRetry.length; i++) {
      _audioPlayerRetry[i].dispose();
    }
    for (int i = 0; i < _audioPlayerBack.length; i++) {
      _audioPlayerBack[i].dispose();
    }
    for (int i = 0; i < _audioPlayerSlide.length; i++) {
      _audioPlayerSlide[i].dispose();
    }
    for (int i = 0; i < _audioPlayerComplete.length; i++) {
      _audioPlayerComplete[i].dispose();
    }
  }
  void setSoundMode(int soundMode) {
    _sound = soundMode;
  }
  int getSoundMode() {
    return _sound;
  }
  String getSoundModeStr(dynamic context) {
    if (_sound == soundOff) {
      return AppLocalizations.of(context).off;
    } else if (_sound == soundOn) {
      return AppLocalizations.of(context).on;
    }
    return '';
  }
  void playSoundStart() async {
    if (_sound != soundOn) {
      return;
    }
    _audioPlayerStartPtr += 1;
    if (_audioPlayerStartPtr >= _audioPlayerStart.length) {
      _audioPlayerStartPtr = 0;
    }
    await _audioPlayerStart[_audioPlayerStartPtr].pause();
    await _audioPlayerStart[_audioPlayerStartPtr].seek(Duration.zero);
    await _audioPlayerStart[_audioPlayerStartPtr].play();
  }
  void playSoundRetry() async {
    if (_sound != soundOn) {
      return;
    }
    _audioPlayerRetryPtr += 1;
    if (_audioPlayerRetryPtr >= _audioPlayerRetry.length) {
      _audioPlayerRetryPtr = 0;
    }
    await _audioPlayerRetry[_audioPlayerRetryPtr].pause();
    await _audioPlayerRetry[_audioPlayerRetryPtr].seek(Duration.zero);
    await _audioPlayerRetry[_audioPlayerRetryPtr].play();
  }
  void playSoundBack() async {
    if (_sound != soundOn) {
      return;
    }
    _audioPlayerBackPtr += 1;
    if (_audioPlayerBackPtr >= _audioPlayerBack.length) {
      _audioPlayerBackPtr = 0;
    }
    await _audioPlayerBack[_audioPlayerBackPtr].pause();
    await _audioPlayerBack[_audioPlayerBackPtr].seek(Duration.zero);
    await _audioPlayerBack[_audioPlayerBackPtr].play();
  }
  void playSoundSlide() async {
    if (_sound != soundOn) {
      return;
    }
    _audioPlayerSlidePtr += 1;
    if (_audioPlayerSlidePtr >= _audioPlayerSlide.length) {
      _audioPlayerSlidePtr = 0;
    }
    await _audioPlayerSlide[_audioPlayerSlidePtr].pause();
    await _audioPlayerSlide[_audioPlayerSlidePtr].seek(Duration.zero);
    await _audioPlayerSlide[_audioPlayerSlidePtr].play();
  }
  void playSoundComplete() async {
    if (_sound != soundOn) {
      return;
    }
    _audioPlayerCompletePtr += 1;
    if (_audioPlayerCompletePtr >= _audioPlayerComplete.length) {
      _audioPlayerCompletePtr = 0;
    }
    await _audioPlayerComplete[_audioPlayerCompletePtr].pause();
    await _audioPlayerComplete[_audioPlayerCompletePtr].seek(Duration.zero);
    await _audioPlayerComplete[_audioPlayerCompletePtr].play();
  }
}

lib/buttons.dart

///
/// @author akira ohmachi
/// @copyright ao-system, Inc.
/// @date 2022-11-26
///

import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';        //flutter gen-l10n

import 'package:cardscalculation/const_value.dart';

class SettingButton {
  IconButton button(BuildContext context, onPressFunc) {
    return IconButton(
      icon: const Icon(Icons.menu, color: ConstValue.colorAppHeaderText),
      tooltip: AppLocalizations.of(context).setting,
      onPressed: onPressFunc,
    );
  }
}

class StartButton {
  ElevatedButton button(BuildContext context, void Function() onPressFunc) {
    return ElevatedButton(
      onPressed: onPressFunc,
      style: ElevatedButton.styleFrom(
        elevation: 0,
        primary: ConstValue.colorAppHeader,
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(0.0)),
        side: const BorderSide(width: 0.5, color: ConstValue.colorAppHeaderLine),
        padding: const EdgeInsets.all(8.0),
      ),
      child: Text(AppLocalizations.of(context).start,
        style: const TextStyle(color: ConstValue.colorAppHeaderText)
      ),
    );
  }
}

class RetryButton {
  ElevatedButton button(BuildContext context, void Function() onPressFunc) {
    return ElevatedButton(
      onPressed: onPressFunc,
      style: ElevatedButton.styleFrom(
        elevation: 0,
        primary: ConstValue.colorAppHeader,
        shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(0.0)),
        side: const BorderSide(width: 0.5, color: ConstValue.colorAppHeaderLine),
        padding: const EdgeInsets.all(8.0),
      ),
      child: Text(AppLocalizations.of(context).retry,
        style: const TextStyle(color: ConstValue.colorAppHeaderText),
      ),
    );
  }
}

class UndoButton {
  ElevatedButton button(BuildContext context, void Function() onPressFunc) {
    return ElevatedButton(
      onPressed: onPressFunc,
      style: ElevatedButton.styleFrom(
        elevation: 0,
        primary: ConstValue.colorAppHeader,
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(0.0)),
        side: const BorderSide(width: 0.5, color: ConstValue.colorAppHeaderLine),
        padding: const EdgeInsets.all(8.0),
      ),
      child: Text(AppLocalizations.of(context).undo,
        style: const TextStyle(color: ConstValue.colorAppHeaderText),
      ),
    );
  }
}

lib/card_all.dart

///
/// @author akira ohmachi
/// @copyright ao-system, Inc.
/// @date 2022-11-26
///

import 'package:cardscalculation/card_one.dart';

class CardAll {
  static final List<CardOne> cards = [
    CardOne(0,1,'assets/image/s1.svg'),
    CardOne(0,2,'assets/image/s2.svg'),
    CardOne(0,3,'assets/image/s3.svg'),
    CardOne(0,4,'assets/image/s4.svg'),
    CardOne(0,5,'assets/image/s5.svg'),
    CardOne(0,6,'assets/image/s6.svg'),
    CardOne(0,7,'assets/image/s7.svg'),
    CardOne(0,8,'assets/image/s8.svg'),
    CardOne(0,9,'assets/image/s9.svg'),
    CardOne(0,10,'assets/image/s10.svg'),
    CardOne(0,11,'assets/image/s11.svg'),
    CardOne(0,12,'assets/image/s12.svg'),
    CardOne(0,13,'assets/image/s13.svg'),
    CardOne(1,1,'assets/image/h1.svg'),
    CardOne(1,2,'assets/image/h2.svg'),
    CardOne(1,3,'assets/image/h3.svg'),
    CardOne(1,4,'assets/image/h4.svg'),
    CardOne(1,5,'assets/image/h5.svg'),
    CardOne(1,6,'assets/image/h6.svg'),
    CardOne(1,7,'assets/image/h7.svg'),
    CardOne(1,8,'assets/image/h8.svg'),
    CardOne(1,9,'assets/image/h9.svg'),
    CardOne(1,10,'assets/image/h10.svg'),
    CardOne(1,11,'assets/image/h11.svg'),
    CardOne(1,12,'assets/image/h12.svg'),
    CardOne(1,13,'assets/image/h13.svg'),
    CardOne(2,1,'assets/image/c1.svg'),
    CardOne(2,2,'assets/image/c2.svg'),
    CardOne(2,3,'assets/image/c3.svg'),
    CardOne(2,4,'assets/image/c4.svg'),
    CardOne(2,5,'assets/image/c5.svg'),
    CardOne(2,6,'assets/image/c6.svg'),
    CardOne(2,7,'assets/image/c7.svg'),
    CardOne(2,8,'assets/image/c8.svg'),
    CardOne(2,9,'assets/image/c9.svg'),
    CardOne(2,10,'assets/image/c10.svg'),
    CardOne(2,11,'assets/image/c11.svg'),
    CardOne(2,12,'assets/image/c12.svg'),
    CardOne(2,13,'assets/image/c13.svg'),
    CardOne(3,1,'assets/image/d1.svg'),
    CardOne(3,2,'assets/image/d2.svg'),
    CardOne(3,3,'assets/image/d3.svg'),
    CardOne(3,4,'assets/image/d4.svg'),
    CardOne(3,5,'assets/image/d5.svg'),
    CardOne(3,6,'assets/image/d6.svg'),
    CardOne(3,7,'assets/image/d7.svg'),
    CardOne(3,8,'assets/image/d8.svg'),
    CardOne(3,9,'assets/image/d9.svg'),
    CardOne(3,10,'assets/image/d10.svg'),
    CardOne(3,11,'assets/image/d11.svg'),
    CardOne(3,12,'assets/image/d12.svg'),
    CardOne(3,13,'assets/image/d13.svg'),
  ];
  void cardsShuffle() {
    cards.shuffle();
  }
  List getCards() {
    return cards;
  }
}

lib/card_one.dart

///
/// @author akira ohmachi
/// @copyright ao-system, Inc.
/// @date 2022-11-26
///

class CardOne {
  int _mark = 0;  //0|1|2|3 特別は-1
  int _num = 0;   //1..13 特別は0
  String _img = '';
  CardOne(int mark, int num, String img) { //constructor
    _mark = mark;
    _num = num;
    _img = img;
  }
  int getMark() {
    return _mark;
  }
  String getColor() {
    if (_mark == 0 || _mark == 2) {
      return 'BLACK';
    }
    if (_mark == 1 || _mark == 3) {
      return 'RED';
    }
    return '';
  }
  int getNum() {
    return _num;
  }
  String getImg() {
    return _img;
  }
  int getIndex() {
    int index = _mark * 13 + _num;
    if (index < 0) {
      return 0;
    }
    return index;  //1..52
  }
}

lib/const_value.dart

///
/// @author akira ohmachi
/// @copyright ao-system, Inc.
/// @date 2022-12-06
///

import 'package:flutter/material.dart';

class ConstValue {
  //const
  static const double canvasAspectRatio = 1 / 1.3;
  static const double menuBarHeight = 56.0;
  //Save.Load value to device
  static const String prefKeySound = 'keySound';
  static const String prefKeyLanguage = "keyLanguage";
  //area name
  static const int areaClose = 1;
  static const int areaOpen = 2;
  static const int areaAce = 3;
  static const int areaStage = 4;
  //color
  static const Color colorAppBackground = Color.fromARGB(255, 55,167,118);
  static const Color colorAppHeader = Color.fromARGB(255, 26,173,108);
  static const Color colorAppHeaderLine = Color.fromARGB(255, 86,240,172);
  static const Color colorAppHeaderText = Color.fromARGB(255, 255, 255, 255);
  static const Color colorAppBody = Color.fromARGB(255, 38,241,154);
  static const Color colorStepNumberOffFore = Color.fromARGB(255, 255,255,255);
  static const Color colorStepNumberOffBack = Color.fromARGB(255, 41,125,88);
  static const Color colorStepNumberOnFore = Color.fromARGB(255, 41,125,88);
  static const Color colorStepNumberOnBack = Color.fromARGB(255, 255,255,0);
  //image
  static const String imageIcon = 'assets/image/icon.svg';
  static const String imageBlank = 'assets/image/blank.svg';
  static const String imageBack = 'assets/image/back.svg';
  //sound
  static const String soundStart = 'assets/sound/start.mp3';
  static const String soundRetry = 'assets/sound/retry.mp3';
  static const String soundBack = 'assets/sound/back.mp3';
  static const String soundSlide = 'assets/sound/slide.mp3';
  static const String soundComplete = 'assets/sound/complete.mp3';
}

lib/drag_animation.dart

///
/// @author akira ohmachi
/// @copyright ao-system, Inc.
/// @date 2022-11-26
///

class DragAnimation {
  List<double> dx = List.generate(53, (i)=>0);  //53個の配列要素数
  List<double> dy = List.generate(53, (i)=>0);
  List<int> speed = List.generate(53, (i)=>0);
  void setX(int i, double num) {
    dx[i] = num;
  }
  void setY(int i, double num) {
    dy[i] = num;
  }
  void addX(int i, double num) {
    dx[i] += num;
  }
  void addY(int i, double num) {
    dy[i] += num;
  }
  double getX(int i) {
    return dx[i];
  }
  double getY(int i) {
    return dy[i];
  }
  void setSpeedOff(int i) {
    speed[i] = 0;
  }
  void setSpeedOn(int i) {
    speed[i] = 200;
    Future.delayed(Duration(milliseconds: speed[i]), () {
      speed[i] = 0;
    });
  }
  int getSpeed(int i) {
    return speed[i];
  }
}

lib/game.dart

///
/// @author akira ohmachi
/// @copyright ao-system, Inc.
/// @date 2022-12-06
///

import 'package:cardscalculation/card_one.dart';
import 'package:cardscalculation/game_history.dart';
import 'package:cardscalculation/const_value.dart';

class Game {
  //const
  static final List<List<String>> joinNumberStrings = [
    ['A','2','3','4','5','6','7','8','9','10','J','Q','K'],
    ['2','4','6','8','10','Q','A','3','5','7','9','J','K'],
    ['3','6','9','Q','2','5','8','J','A','4','7','10','K'],
    ['4','8','Q','3','7','J','2','6','10','A','5','9','K'],
  ];
  static final List<List<int>> joinNumberInts = [
    [1,2,3,4,5,6,7,8,9,10,11,12,13],
    [2,4,6,8,10,12,1,3,5,7,9,11,13],
    [3,6,9,12,2,5,8,11,1,4,7,10,13],
    [4,8,12,3,7,11,2,6,10,1,5,9,13],
  ];
  //
  final CardOne cardOneBlank = CardOne(-1, 0, ConstValue.imageBlank);
  List<List<CardOne>> cardAce = [[],[],[],[]];
  List<CardOne> cardClose = [];
  List<CardOne> cardOpen = [];
  List<List<CardOne>> cardStage = [
    [],[],[],[],
  ];
  final GameHistory gameHistory = GameHistory();
  Game() {  //constructor
    init();
  }
  void init() {
    cardAce = [
      [cardOneBlank],
      [cardOneBlank],
      [cardOneBlank],
      [cardOneBlank],
    ];
    cardClose = [cardOneBlank];
    cardOpen = [cardOneBlank];
    cardStage = [
      [cardOneBlank],
      [cardOneBlank],
      [cardOneBlank],
      [cardOneBlank],
    ];
    gameHistory.init();
  }
  List<List<CardOne>> getCardAce() {
    return cardAce;
  }
  List<CardOne> getCardClose() {
    return cardClose;
  }
  List<CardOne> getCardOpen() {
    return cardOpen;
  }
  List<List<CardOne>> getCardStage() {
    return cardStage;
  }
  void cardMoveFromCloseToOpen(CardOne dragCard) {
    if (cardClose.length > 1 && cardOpen.length == 1) {
      cardClose.removeLast();
      cardOpen.add(dragCard);
      gameHistory.historyPush(dragCard, ConstValue.areaClose, 0, ConstValue.areaOpen, 0);
      return;
    }
  }
  void cardMoveToAce(int column, CardOne dragCard) {
    //重ねたのが open area のカードだった場合
    if (dragCard == cardOpen.last) {
      cardOpen.removeLast();
      cardAce[column].add(dragCard);
      gameHistory.historyPush(dragCard, ConstValue.areaOpen, 0, ConstValue.areaAce, column);
      return;
    }
    //重ねたのが stage area のカードだった場合
    for (int x = 0; x < 4; x++) {
      if (cardStage[x][cardStage[x].length - 1] == dragCard) {
        cardStage[x].removeLast();
        cardAce[column].add(dragCard);
        gameHistory.historyPush(dragCard, ConstValue.areaStage, x, ConstValue.areaAce, column);
        return;
      }
    }
  }
  //stage area へ移動
  void cardMoveFromOpenToStage(int column, CardOne dragCard) {
    cardOpen.removeLast();
    cardStage[column].add(dragCard);
    gameHistory.historyPush(dragCard, ConstValue.areaOpen, 0, ConstValue.areaStage, column);
  }
  //undo
  void historyUndo() {
    CardMoveRecord? cardMoveRecord = gameHistory.historyPop();
    if (cardMoveRecord == null) {
      return;
    }
    final CardOne cardOne = cardMoveRecord.getCard();
    final int fromArea = cardMoveRecord.getFromArea();
    final int fromColumn = cardMoveRecord.getFromColumn();
    final int toArea = cardMoveRecord.getToArea();
    final int toColumn = cardMoveRecord.getToColumn();
    if (toArea == ConstValue.areaOpen) {
      cardOpen.removeLast();
    } else if (toArea == ConstValue.areaAce) {
      cardAce[toColumn].removeLast();
    } else if (toArea == ConstValue.areaStage) {
      cardStage[toColumn].removeLast();
    }
    if (fromArea == ConstValue.areaClose) {
      cardClose.add(cardOne);
      historyUndo();
    } else if (fromArea == ConstValue.areaOpen) {
      cardOpen.add(cardOne);
    } else if (fromArea == ConstValue.areaStage) {
      cardStage[fromColumn].add(cardOne);
    }
  }
  bool isComplete() {
    return (cardAce[0].length == 14 && cardAce[1].length == 14 && cardAce[2].length == 14 && cardAce[3].length == 14) ? true : false;
  }
}

lib/game_history.dart

///
/// @author akira ohmachi
/// @copyright ao-system, Inc.
/// @date 2022-11-26
///

import 'package:cardscalculation/card_one.dart';

class GameHistory {
  List<CardMoveRecord> history = [];
  GameHistory() { //constructor
    init();
  }
  void init() {
    history = [];
  }
  void historyPush(CardOne moveCard, int moveFromArea, int moveFromColumn, int moveToArea, int moveToColumn) {
    history.add(CardMoveRecord(moveCard, moveFromArea, moveFromColumn, moveToArea, moveToColumn));
  }
  CardMoveRecord? historyPop() {
    if (history.isEmpty) {
      return null;
    }
    CardMoveRecord cardMoveRecord = history[history.length - 1];
    history.removeLast();
    return cardMoveRecord;
  }
  int getLength() {
    return history.length;
  }
}

class CardMoveRecord {
  late CardOne cardOne;
  late int fromArea;   //areaFree|areaAce|areaStage
  late int fromColumn;
  late int toArea;   //areaFree|areaAce|areaStage
  late int toColumn;
  CardMoveRecord(CardOne moveCard, int moveFromArea, int moveFromColumn, int moveToArea, int moveToColumn) {  //constructor
    cardOne = moveCard;
    fromArea = moveFromArea;
    fromColumn = moveFromColumn;
    toArea = moveToArea;
    toColumn = moveToColumn;
  }
  CardOne getCard() {
    return cardOne;
  }
  int getFromArea() {
    return fromArea;
  }
  int getFromColumn() {
    return fromColumn;
  }
  int getToArea() {
    return toArea;
  }
  int getToColumn() {
    return toColumn;
  }
}

lib/language_choice.dart

///
/// @author akira ohmachi
/// @copyright ao-system, Inc.
/// @date 2022-11-26
///

import 'package:flutter/material.dart';

class LanguageChoice {
  final Map<String,String> langMap = {
    'en': 'English',
    'bg': 'български език',
    'cs': 'Čeština',
    'da': 'dansk',
    'de': 'Deutsch',
    'el': 'Ελληνικά',
    'es': 'Español',
    'et': 'eesti keel',
    'fi': 'Suomen kieli',
    'fr': 'Français',
    'hu': 'magyar nyelv',
    'it': 'Italiano',
    'ja': '日本語',
    'lt': 'lietuvių kalba',
    'lv': 'Latviešu',
    'nl': 'Nederlands',
    'pl': 'Polski',
    'pt': 'Português',
    'ro': 'limba română',
    'ru': 'русский',
    'sk': 'Slovenčina',
    'sv': 'svenska',
    'th': 'ภาษาไทย',
    'zh': '中文',
  };
  List<String> languageList() {
    List<String> languages = [];
    langMap.forEach((key, value) {
      languages.add(key);
    });
    return languages;
  }
  String getLanguageName(String str) {
    if (langMap.containsKey(str)) {
      return langMap[str]!;
    }
    return '';
  }
  List<Locale> localeList() {
    List<Locale> locales = [];
    langMap.forEach((key, value) {
      locales.add(Locale(key));
    });
    return locales;
  }
}

lib/main.dart

///
/// @author akira ohmachi
/// @copyright ao-system, Inc.
/// @date 2022-12-04
///

import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_svg/svg.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';        //flutter gen-l10n
import 'package:package_info_plus/package_info_plus.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'dart:async';

import 'package:cardscalculation/language_choice.dart';
import 'package:cardscalculation/ad_mob.dart';
import 'package:cardscalculation/audio_play.dart';
import 'package:cardscalculation/card_all.dart';
import 'package:cardscalculation/card_one.dart';
import 'package:cardscalculation/drag_animation.dart';
import 'package:cardscalculation/buttons.dart';
import 'package:cardscalculation/game.dart';
import 'package:cardscalculation/const_value.dart';
import 'package:cardscalculation/app_condition.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  //SystemChrome.setPreferredOrientations([
  //  DeviceOrientation.portraitUp, //縦固定
  //]);
  MobileAds.instance.initialize();
  runApp(const MainApp());
}

class MainApp extends StatefulWidget {
  const MainApp({super.key});
  @override
  State<MainApp> createState() => _MainAppState();
}

class _MainAppState extends State<MainApp> {
  Locale locale = AppLocalizations.supportedLocales.first;
  @override
  Widget build(BuildContext context) {
    final LanguageChoice languageChoice = LanguageChoice();
    final List<Locale> localeList = languageChoice.localeList();
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      localizationsDelegates: const [
        AppLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: localeList,
      locale: locale,
      home: const MainPage(),
    );
  }
}

class MainPage extends StatefulWidget {
  const MainPage({Key? key}) : super(key: key);
  @override
  State<MainPage> createState() => _MainPageState();
}

//-------------------------------------------------

class _MainPageState extends State<MainPage> {
  final GlobalKey<ScaffoldState> _key = GlobalKey<ScaffoldState>();
  final AppCondition appCondition = AppCondition();
  final AdMob adMob = AdMob();
  final AudioPlay audioPlay = AudioPlay();
  final CardAll cardAll = CardAll();
  final Game game = Game();
  final DragAnimation dragAnimation = DragAnimation();

  @override
  void initState() {
    super.initState();
    _getVersion();
    _loadSound();
    _loadLanguage();
    adMob.load();
  }
  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    _storeAppCanvasWidth(false);
    _onClickStartButton();
  }
  @override
  Widget build(BuildContext context) {
    _storeAppCanvasWidth(false);
    return Scaffold(
      key: _key,
      appBar: null,
      drawer: _hamburgerMenu(),
      backgroundColor: ConstValue.colorAppBackground,
      body: OrientationBuilder(builder: (context, orientation) {
        _storeAppCanvasWidth(true);
        return SafeArea(
          child: Center(
            child: Column(
              children: [
                _menuBar(),
                Expanded(
                  child: Container(
                    color: ConstValue.colorAppBody,
                    padding: const EdgeInsets.symmetric(horizontal: 8.0,vertical: 8.0),
                    child: Center(
                      child: AspectRatio(
                        aspectRatio: ConstValue.canvasAspectRatio,
                        child: Container(
                          width: double.infinity,
                          height: double.infinity,
                          color: ConstValue.colorAppBody,
                          child: _boxCanvas(),
                        ),
                      ),
                    ),
                  ),
                ),
                Container(
                  width: double.infinity,
                  color: ConstValue.colorAppBody,
                  child: adMob.getAdBannerWidget(),
                ),
              ]
            ),
          )
        );
      }),
    );
  }
  //@override
  //void didUpdateWidget(MainPage oldWidget) {
  //  super.didUpdateWidget(oldWidget);
  //}
  @override
  void dispose() {
    audioPlay.dispose();
    super.dispose();
  }

  //-----------------------------------------------

  Future<void> _getVersion() async {
    final PackageInfo packageInfo = await PackageInfo.fromPlatform();
    setState(() {
      appCondition.setAppVersion(packageInfo.version);
    });
  }
  void _storeAppCanvasWidth(bool reDraw) {
    SchedulerBinding.instance.addPostFrameCallback((_) {
      final double sizeWidth = _key.currentContext!.size!.width;
      final double margin = sizeWidth * 0.025;
      final double w = _key.currentContext!.size!.width - margin;
      final double h = _key.currentContext!.size!.height - margin - ConstValue.menuBarHeight - adMob.getAdBannerHeight();
      double appWidth = w;
      if (w / ConstValue.canvasAspectRatio > h) {
        appWidth = (h / (w / ConstValue.canvasAspectRatio)) * w;
      }
      appCondition.setCanvasWidth(appWidth.floorToDouble());
      if (reDraw) { //画面幅取得は非同期なので取得出来たら再描画
        setState(() {});
      }
    });
  }
  void _loadLanguage() async {
    final SharedPreferences prefs = await SharedPreferences.getInstance();
    final String lang = prefs.getString(ConstValue.prefKeyLanguage) ?? 'en';
    if (!mounted) {
      return;
    }
    context.findAncestorStateOfType<_MainAppState>()!
      ..locale = Locale(lang)
      ..setState(() {});
  }
  void _saveLanguage(String lang) async {
    final SharedPreferences prefs = await SharedPreferences.getInstance();
    prefs.setString(ConstValue.prefKeyLanguage, lang);
  }
  void _loadSound() async {
    final SharedPreferences prefs = await SharedPreferences.getInstance();
    setState(() {
      audioPlay.setSoundMode(prefs.getInt(ConstValue.prefKeySound) ?? AudioPlay.soundOn);
    });
  }
  void _saveSound() async {
    final SharedPreferences prefs = await SharedPreferences.getInstance();
    setState(() {
      prefs.setInt(ConstValue.prefKeySound, audioPlay.getSoundMode());
    });
  }
  void _onClickStartButton() {
    audioPlay.playSoundStart();
    cardAll.cardsShuffle();
    setState(() {
      _handOut();
    });
  }
  void _onClickRetryButton() {
    audioPlay.playSoundRetry();
    setState(() {
      _handOut();
    });
  }
  void _onClickUndoButton() {
    audioPlay.playSoundBack();
    setState(() {
      game.historyUndo();
    });
  }

  //カードを配る
  void _handOut() {
    final List cards = cardAll.getCards();
    game.init();
    List<bool> aceSets = [false,false,false,false];
    for (int i = 0; i < 52; i++) {
      final CardOne card = cards[i];
      final int cardNum = card.getNum();
      if (aceSets[0] == false && cardNum == 1) {
        game.cardAce[0].add(card);
        aceSets[0] = true;
      } else if (aceSets[1] == false && cardNum == 2) {
        game.cardAce[1].add(card);
        aceSets[1] = true;
      } else if (aceSets[2] == false && cardNum == 3) {
        game.cardAce[2].add(card);
        aceSets[2] = true;
      } else if (aceSets[3] == false && cardNum == 4) {
        game.cardAce[3].add(card);
        aceSets[3] = true;
      } else if (i == 51) {
        game.cardOpen.add(card);
      } else {
        game.cardClose.add(card);
      }
    }
  }

  //-----------------------------------------------

  Widget _dialogSound() {
    return SimpleDialog(
      title: Text('${AppLocalizations.of(context).sound}: ${audioPlay.getSoundModeStr(context)}'),
      children: <Widget>[
        SimpleDialogOption(
            child: Text(AppLocalizations.of(context).off),
            onPressed: () {
              setState(() {
                audioPlay.setSoundMode(AudioPlay.soundOff);
              });
              _saveSound();
              Navigator.pop(context);
            }
        ),
        SimpleDialogOption(
            child: Text(AppLocalizations.of(context).on),
            onPressed: () {
              setState(() {
                audioPlay.setSoundMode(AudioPlay.soundOn);
              });
              _saveSound();
              Navigator.pop(context);
            }
        ),
      ],
    );
  }
  Widget _dialogLanguage() {
    final LanguageChoice languageChoice = LanguageChoice();
    final List<String> langList = languageChoice.languageList();
    return SimpleDialog(
      title: Text(AppLocalizations.of(context).language),
      children: List.generate(langList.length,(index) {
        return SimpleDialogOption(
            child: Row(
                children:[
                  SizedBox(
                      width: 25,
                      child: Text(langList[index])
                  ),
                  Text('- ${languageChoice.getLanguageName(langList[index])}')
                ]
            ),
            onPressed: () {
              _saveLanguage(langList[index]);
              context.findAncestorStateOfType<_MainAppState>()!
                ..locale = Locale(langList[index])
                ..setState((){});
              Navigator.pop(context);
            }
        );
      }),
    );
  }
  Widget _hamburgerMenu() {
    return Drawer(
      child: ListView(
        padding: EdgeInsets.zero,
        children: [
          SizedBox(
              height: 230,
              child: DrawerHeader(
                decoration: const BoxDecoration(color: ConstValue.colorAppHeader),
                child: Column(children:[
                  Row(children:[
                    SvgPicture.asset(ConstValue.imageIcon, width: 80, height: 80),
                    const SizedBox(width: 8),
                    Flexible(child: Text(AppLocalizations.of(context).appName,style: const TextStyle(color: Colors.white))),
                  ]),
                  Text(AppLocalizations.of(context).usage,style: const TextStyle(fontSize: 11,color: Colors.white)),
                ]),
              )
          ),
          ListTile(
            leading: const CircleAvatar(
              backgroundColor: ConstValue.colorAppHeader,
              child: Icon(
                Icons.audiotrack,
                color: ConstValue.colorAppHeaderText,
              ),
            ),
            title: Text('${AppLocalizations.of(context).sound}: ${audioPlay.getSoundModeStr(context)}'),
            trailing: const Icon(
              Icons.arrow_circle_right_outlined,
            ),
            onTap: () {
              showDialog(
                  context: context,
                  barrierDismissible: true,
                  builder: (_) {
                    return _dialogSound();
                  }
              );
            },
          ),
          Container(
            padding: const EdgeInsets.only(left: 15,right: 15,bottom: 20),
            child: Text(AppLocalizations.of(context).sound1,style: const TextStyle(fontSize: 11,color: Colors.black54)),
          ),
          ListTile(
            leading: const CircleAvatar(
              backgroundColor: ConstValue.colorAppHeader,
              child: Icon(
                Icons.language,
                color: ConstValue.colorAppHeaderText,
              ),
            ),
            title: Text(AppLocalizations.of(context).language),
            trailing: const Icon(
              Icons.arrow_circle_right_outlined,
            ),
            onTap: () {
              showDialog(
                  context: context,
                  barrierDismissible: true,
                  builder: (_) {
                    return _dialogLanguage();
                  }
              );
            },
          ),
          Container(
            padding: const EdgeInsets.only(left: 15,right: 15,top: 50),
            child: Text('v ${appCondition.getAppVersion()}',style: const TextStyle(fontSize: 11,color: Colors.black45)),
          ),
        ],
      ),
    );
  }
  Widget _menuBar() {
    return Container(
      height: ConstValue.menuBarHeight, // in logical pixels
      padding: const EdgeInsets.symmetric(horizontal: 8.0),
      decoration: const BoxDecoration(color: ConstValue.colorAppHeader),
      child: Row(
        children: <Widget> [
          StartButton().button(context,_onClickStartButton),
          const SizedBox(width: 8),
          RetryButton().button(context,_onClickRetryButton),
          const SizedBox(width: 8),
          UndoButton().button(context,_onClickUndoButton),
          const Expanded(
            child: SizedBox(width: 8),
          ),
          SettingButton().button(context,(){_key.currentState?.openDrawer();}),
        ],
      ),
    );
  }

  //-------------------------------------------------------------

  Widget _boxCanvas() {
    final double canvasWidth = appCondition.getCanvasWidth();
    final double widthCardGap = (canvasWidth / 67).floorToDouble();
    final double widthCardNum = widthCardGap * 5;
    double widthCardOne = widthCardGap * 10;
    if (widthCardOne > 1) {
      widthCardOne -= 2.0; //なぜかはみ出るから微調整
    }
    return Column(
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Column(children: _cardNum(0,widthCardNum)),
            Container(width: widthCardGap),
            Stack(children: _cardAceImage(0,widthCardOne)),
            Container(width: widthCardGap),
            Column(children: _cardNum(1,widthCardNum)),
            Container(width: widthCardGap),
            Stack(children: _cardAceImage(1,widthCardOne)),
            Container(width: widthCardGap),
            Column(children: _cardNum(2,widthCardNum)),
            Container(width: widthCardGap),
            Stack(children: _cardAceImage(2,widthCardOne)),
            Container(width: widthCardGap),
            Column(children: _cardNum(3,widthCardNum)),
            Container(width: widthCardGap),
            Stack(children: _cardAceImage(3,widthCardOne)),
          ],
        ),
        Container(height: widthCardGap * 3),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Stack(children: _cardCloseImage(widthCardOne)),
            Container(width: widthCardGap),
            Stack(children: _cardOpenImage(widthCardOne)),
            Container(width: widthCardGap * 4),
            Stack(children: _cardStageImage(0,widthCardOne)),
            Container(width: widthCardGap),
            Stack(children: _cardStageImage(1,widthCardOne)),
            Container(width: widthCardGap),
            Stack(children: _cardStageImage(2,widthCardOne)),
            Container(width: widthCardGap),
            Stack(children: _cardStageImage(3,widthCardOne)),
          ],
        ),
      ],
    );
  }
  List<Widget> _cardNum(int index, double widthCardNum) {
    final List<List<CardOne>> cardAce = game.getCardAce();
    final int cardAceLength = cardAce[index].length;
    final List<Widget> containerArray = [];
    for (int x = 0; x < 13; x++) {
      if (x == cardAceLength - 1) {
        final Container container = Container(
          width: widthCardNum,
          decoration: const BoxDecoration(color: ConstValue.colorStepNumberOnBack),
          child: Text(Game.joinNumberStrings[index][x],
            textAlign: TextAlign.center,
            style: const TextStyle(
              color: ConstValue.colorStepNumberOnFore,
              fontSize: 15,
            ),
          ),
        );
        containerArray.add(container);
      } else {
        final Container container = Container(
          width: widthCardNum,
          decoration: const BoxDecoration(color: ConstValue.colorStepNumberOffBack),
          child: Text(Game.joinNumberStrings[index][x],
            textAlign: TextAlign.center,
            style: const TextStyle(
              color: ConstValue.colorStepNumberOffFore,
              fontSize: 15,
            ),
          ),
        );
        containerArray.add(container);
      }
    }
    return containerArray;
  }
  List<Widget> _cardAceImage(int index, double widthCardOne) {
    bool isAceCardJoin(int index, CardOne dragCard) {
      final List<List<CardOne>> cardAce = game.getCardAce();
      final int cardAceLength = cardAce[index].length;
      if (cardAceLength >= 14) {
        return false;
      }
      final int nextNum = Game.joinNumberInts[index][cardAceLength - 1];
      final int dragNum = dragCard.getNum();
      if (dragNum == nextNum) {
        return true;
      }
      return false;
    }
    final List<List<CardOne>> cardAce = game.getCardAce();
    final List<Container> containerArray = [];
    for (int y = 0; y < cardAce[index].length; y++) {
      final String cardImg = cardAce[index][y].getImg();
      final double marginTop = (y <= 1) ? 0 : (y - 1) * (widthCardOne * 0.35);
      final Container container = Container(
        margin: EdgeInsets.only(top: marginTop),
        child: SvgPicture.asset(
          cardImg,
          width: widthCardOne,
        ),
      );
      containerArray.add(container);
    }
    final double marginTop = (cardAce[index].length <= 1) ? 0 : (cardAce[index].length - 1) * (widthCardOne * 0.35);
    final Container containerDragArea = Container(
      margin: EdgeInsets.only(top: marginTop),
      child: DragTarget<CardOne>(
        builder: (context, accepted, rejected) {
          return Container(
            width: widthCardOne,
            height: widthCardOne / 360 * 540,
            //color: Colors.grey.withOpacity(0.5),
          );
        },
        onWillAccept: (data) {
          return isAceCardJoin(index, data!);
        },
        onAccept: (data) {
          game.cardMoveToAce(index, data);
          cardMoveFormCloseToOpen();
          if (game.isComplete()) {
            audioPlay.playSoundComplete();
          }
        },
      )
    );
    containerArray.add(containerDragArea);
    return containerArray;
  }
  List<Widget> _cardCloseImage(double widthCardOne) {
    final List<CardOne> cardClose = game.getCardClose();
    final List<Container> containerArray = [];
    for (int y = 0; y < cardClose.length; y++) {
      final String cardImg = cardClose[y].getImg();
      final int cardNum = cardClose[y].getNum();
      final double marginTop = (y <= 1) ? 0 : (y - 1) * (widthCardOne * 0.05);
      if (cardNum >= 1) {
        final Container container = Container(
          margin: EdgeInsets.only(top: marginTop),
          child: SvgPicture.asset(
            ConstValue.imageBack,
            width: widthCardOne,
          ),
        );
        containerArray.add(container);
      } else {
        final Container container = Container(
          margin: EdgeInsets.only(top: marginTop),
          child: SvgPicture.asset(
            cardImg,
            width: widthCardOne,
          ),
        );
        containerArray.add(container);
      }
    }
    return containerArray;
  }
  List<Widget> _cardOpenImage(double widthCardOne) {
    final List<CardOne> cardOpen = game.getCardOpen();
    final List<Widget> containerArray = [];
    if (cardOpen.isNotEmpty) { //1枚目(blank)
      final String cardImg = cardOpen[0].getImg();
      final Container container = Container(
        child: SvgPicture.asset(
          cardImg,
          width: widthCardOne,
        ),
      );
      containerArray.add(container);
    }
    if (cardOpen.length >= 2) { //2枚目(card)
      final String cardImg = cardOpen[1].getImg();
      final int cardIndex = cardOpen[1].getIndex();
      final AnimatedPositioned container = AnimatedPositioned(
        left: dragAnimation.getX(cardIndex),
        top: dragAnimation.getY(cardIndex),
        duration: Duration(milliseconds: dragAnimation.getSpeed(cardIndex)),
        child: Container(
          child: Draggable(
            data: cardOpen[1],
            onDragStarted: () {
              audioPlay.playSoundSlide();
            },
            feedback: SvgPicture.asset(
              cardImg,
              width: widthCardOne,
            ),
            childWhenDragging: Container(),
            child: SvgPicture.asset(
              cardImg,
              width: widthCardOne,
            ),
            onDragUpdate: (details) {
              dragAnimation.setSpeedOff(cardIndex);
              dragAnimation.addX(cardIndex,details.delta.dx);
              dragAnimation.addY(cardIndex,details.delta.dy);
            },
            onDragEnd: (details) {
              dragAnimation.setSpeedOn(cardIndex);
              dragAnimation.setX(cardIndex,0);
              dragAnimation.setY(cardIndex,0);
            },
          ),
        ),
      );
      containerArray.add(container);
    }
    return containerArray;
  }
  List<Widget> _cardStageImage(int index, double widthCardOne) {
    final List<List<CardOne>> cardStage = game.getCardStage();
    final List<Widget> containerArray = [];
    for (int y = 0; y < cardStage[index].length; y++) {
      final String cardImg = cardStage[index][y].getImg();
      final int cardIndex = cardStage[index][y].getIndex();
      double marginTop = 0;
      if (cardStage[index].length >= 13) {
        marginTop = (y <= 1) ? 0 : (y - 1) * (widthCardOne * 0.2);
      } else {
        marginTop = (y <= 1) ? 0 : (y - 1) * (widthCardOne * 0.35);
      }
      if (y != 0 && y == cardStage[index].length - 1) { //列の最後のカード
        final AnimatedPositioned container = AnimatedPositioned(
          left: dragAnimation.getX(cardIndex),
          top: dragAnimation.getY(cardIndex),
          duration: Duration(milliseconds: dragAnimation.getSpeed(cardIndex)),
          child: Container(
            margin: EdgeInsets.only(top: marginTop),
            child: Draggable(
              data: cardStage[index][y],
              onDragStarted: () {
                audioPlay.playSoundSlide();
              },
              feedback: SvgPicture.asset(
                cardImg,
                width: widthCardOne,
              ),
              childWhenDragging: Container(),
              child: SvgPicture.asset(
                cardImg,
                width: widthCardOne,
              ),
              onDragUpdate: (details) {
                dragAnimation.setSpeedOff(cardIndex);
                dragAnimation.addX(cardIndex,details.delta.dx);
                dragAnimation.addY(cardIndex,details.delta.dy);
              },
              onDragEnd: (details) {
                dragAnimation.setSpeedOn(cardIndex);
                dragAnimation.setX(cardIndex,0);
                dragAnimation.setY(cardIndex,0);
              },
            ),
          ),
        );
        containerArray.add(container);
      } else {  //列の中のカード(動かせないカード)
        final Container container = Container(
          margin: EdgeInsets.only(top: marginTop),
          child: SvgPicture.asset(
            cardImg,
            width: widthCardOne,
          ),
        );
        containerArray.add(container);
      }
    }
    double marginTop = 0;
    if (cardStage[index].length >= 13) {
      marginTop = (cardStage[index].length - 1) * (widthCardOne * 0.2);
    } else {
      marginTop = (cardStage[index].length - 1) * (widthCardOne * 0.35);
    }
    final Container containerDragArea = Container(
      margin: EdgeInsets.only(top: marginTop),
      child: DragTarget<CardOne>(
        builder: (context, accepted, rejected) {
          return SizedBox(
            width: widthCardOne,
            height: widthCardOne / 360 * 540,
            //color: Colors.grey.withOpacity(0.5),
          );
        },
        onWillAccept: (data) {
          return (data == game.cardOpen.last) ? true : false;
        },
        onAccept: (data) {
          game.cardMoveFromOpenToStage(index, data);
          cardMoveFormCloseToOpen();
        },
      ),
    );
    containerArray.add(containerDragArea);
    return containerArray;
  }
  void cardMoveFormCloseToOpen() {
    final List<CardOne> cardClose = game.getCardClose();
    debugPrint(cardClose.length.toString());
    if (cardClose.length > 1) {
      game.cardMoveFromCloseToOpen(cardClose.last);
    }
  }

}
このページでお気付きの点がございましたら
ご連絡いただけますと幸いです。
Eメール(任意)
送信内容
 

便利ウェブサイト