-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
362 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"file_generated_by": "FlutterFire CLI", | ||
"purpose": "FirebaseAppID & ProjectID for this Firebase app in this directory", | ||
"GOOGLE_APP_ID": "1:807943088200:ios:125d7bfaa751582d21907d", | ||
"FIREBASE_PROJECT_ID": "tic-tac-toe-handson", | ||
"GCM_SENDER_ID": "807943088200" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// File generated by FlutterFire CLI. | ||
// ignore_for_file: lines_longer_than_80_chars, avoid_classes_with_only_static_members | ||
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions; | ||
import 'package:flutter/foundation.dart' | ||
show defaultTargetPlatform, kIsWeb, TargetPlatform; | ||
|
||
/// Default [FirebaseOptions] for use with your Firebase apps. | ||
/// | ||
/// Example: | ||
/// ```dart | ||
/// import 'firebase_options.dart'; | ||
/// // ... | ||
/// await Firebase.initializeApp( | ||
/// options: DefaultFirebaseOptions.currentPlatform, | ||
/// ); | ||
/// ``` | ||
class DefaultFirebaseOptions { | ||
static FirebaseOptions get currentPlatform { | ||
if (kIsWeb) { | ||
return web; | ||
} | ||
switch (defaultTargetPlatform) { | ||
case TargetPlatform.android: | ||
return android; | ||
case TargetPlatform.iOS: | ||
return ios; | ||
case TargetPlatform.macOS: | ||
return macos; | ||
case TargetPlatform.windows: | ||
throw UnsupportedError( | ||
'DefaultFirebaseOptions have not been configured for windows - ' | ||
'you can reconfigure this by running the FlutterFire CLI again.', | ||
); | ||
case TargetPlatform.linux: | ||
throw UnsupportedError( | ||
'DefaultFirebaseOptions have not been configured for linux - ' | ||
'you can reconfigure this by running the FlutterFire CLI again.', | ||
); | ||
default: | ||
throw UnsupportedError( | ||
'DefaultFirebaseOptions are not supported for this platform.', | ||
); | ||
} | ||
} | ||
|
||
static const FirebaseOptions web = FirebaseOptions( | ||
apiKey: 'AIzaSyAoY0U1veRmqWWMmFBULkerX6X5HYjMmIs', | ||
appId: '1:807943088200:web:eda1735cfd79d15e21907d', | ||
messagingSenderId: '807943088200', | ||
projectId: 'tic-tac-toe-handson', | ||
authDomain: 'tic-tac-toe-handson.firebaseapp.com', | ||
storageBucket: 'tic-tac-toe-handson.appspot.com', | ||
); | ||
|
||
static const FirebaseOptions android = FirebaseOptions( | ||
apiKey: 'AIzaSyCCWnRieFsedimIvgsjNevAdUSb0dm1faY', | ||
appId: '1:807943088200:android:d989c8a1b020562321907d', | ||
messagingSenderId: '807943088200', | ||
projectId: 'tic-tac-toe-handson', | ||
storageBucket: 'tic-tac-toe-handson.appspot.com', | ||
); | ||
|
||
static const FirebaseOptions ios = FirebaseOptions( | ||
apiKey: 'AIzaSyBZHELrAr4SRfXLYrxc4zF27P0R3sGsbi0', | ||
appId: '1:807943088200:ios:125d7bfaa751582d21907d', | ||
messagingSenderId: '807943088200', | ||
projectId: 'tic-tac-toe-handson', | ||
storageBucket: 'tic-tac-toe-handson.appspot.com', | ||
iosBundleId: 'com.example.ticTacToeHandson', | ||
); | ||
|
||
static const FirebaseOptions macos = FirebaseOptions( | ||
apiKey: 'AIzaSyBZHELrAr4SRfXLYrxc4zF27P0R3sGsbi0', | ||
appId: '1:807943088200:ios:125d7bfaa751582d21907d', | ||
messagingSenderId: '807943088200', | ||
projectId: 'tic-tac-toe-handson', | ||
storageBucket: 'tic-tac-toe-handson.appspot.com', | ||
iosBundleId: 'com.example.ticTacToeHandson', | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Players { | ||
final String playerX; | ||
final String playerO; | ||
|
||
Players({ | ||
required this.playerX, | ||
required this.playerO, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,8 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:tic_tac_toe_handson/model/tic_tac_toe.dart'; | ||
import 'package:tic_tac_toe_handson/repository/tic_tac_toe_repository.dart'; | ||
|
||
final ticTacToeProvider = StateNotifierProvider.autoDispose<TicTacToeProvider, TicTacToe>((ref) { | ||
return TicTacToeProvider(); | ||
final ticTacToeProvider = StreamProvider.autoDispose<TicTacToe>((ref) { | ||
// 対戦相手同士のIDを設定する | ||
return getTicTacToe(playerX: 'flutter', playerO: 'kaigi'); | ||
}); | ||
|
||
class TicTacToeProvider extends StateNotifier<TicTacToe> { | ||
TicTacToeProvider() : super(TicTacToe.start()); | ||
|
||
placeMark(int row, int col) { | ||
state = state.placeMark(row, col); | ||
} | ||
|
||
resetBoard() { | ||
state = state.resetBoard(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:cloud_firestore/cloud_firestore.dart'; | ||
import 'package:tic_tac_toe_handson/model/tic_tac_toe.dart'; | ||
|
||
final client = FirebaseFirestore.instance; | ||
const rootCollectionKey = 'tic_tac_toe'; | ||
|
||
Stream<TicTacToe> getTicTacToe({String playerX = 'X', String playerO = 'O'}) { | ||
final documentKey = _documentKey(playerX, playerO); | ||
return client.collection(rootCollectionKey).doc(documentKey).snapshots().map((snapshot) { | ||
final data = snapshot.data(); | ||
if (data == null) { | ||
return TicTacToe.start(playerX: playerX, playerO: playerO); | ||
} | ||
|
||
return TicTacToe.fromJson(data); | ||
}); | ||
} | ||
|
||
Future<void> updateTicTacToe(TicTacToe ticTacToe) async { | ||
final documentKey = _documentKey(ticTacToe.players.playerX, ticTacToe.players.playerO); | ||
await client.collection(rootCollectionKey).doc(documentKey).set(ticTacToe.toJson()); | ||
} | ||
|
||
String _documentKey(String playerX, String playerO) { | ||
return '${playerX}_${playerO}'; | ||
} |
Oops, something went wrong.