Skip to content

Commit

Permalink
Googleアカウントでのログイン機能の追加 issue #3
Browse files Browse the repository at this point in the history
ログアウト機能の追加issue #4
  • Loading branch information
t-kawauchiya committed Mar 30, 2021
1 parent 8561ab9 commit d6bd44f
Show file tree
Hide file tree
Showing 14 changed files with 252 additions and 126 deletions.
3 changes: 3 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,7 @@ flutter {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.firebase:firebase-core:16.0.0'
}

apply plugin: 'com.google.gms.google-services'
46 changes: 46 additions & 0 deletions android/app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"project_info": {
"project_number": "147699414018",
"project_id": "training-app-7a96a",
"storage_bucket": "training-app-7a96a.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:147699414018:android:2d2d4be284838cc634231b",
"android_client_info": {
"package_name": "com.example.training_app"
}
},
"oauth_client": [
{
"client_id": "147699414018-h5bn9oo6i2g1hbqsdao2o068l6cetju0.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyBU84jgyaP4hRytKwb9g7be1BFh8s4pC8g"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "147699414018-h5bn9oo6i2g1hbqsdao2o068l6cetju0.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "147699414018-iqk5i6nmok3bc4pont6t4e0rpvtt8b0v.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "com.example.trainingApp"
}
}
]
}
}
}
],
"configuration_version": "1"
}
4 changes: 4 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
Expand Down
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.0.0'
}
}

Expand Down
1 change: 0 additions & 1 deletion ios/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Flutter/flutter_assets/
Flutter/flutter_export_environment.sh
ServiceDefinitions.json
Runner/GeneratedPluginRegistrant.*
Runner/GoogleService-Info.plist

# Exceptions to above rules.
!default.mode1v3
Expand Down
18 changes: 18 additions & 0 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
9C36CDDE6298564E8F302DE9 /* [CP] Embed Pods Frameworks */,
7C2A4CFAF699D1EF7CA53702 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -237,6 +238,23 @@
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin";
};
7C2A4CFAF699D1EF7CA53702 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n";
showEnvVarsInLog = 0;
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down
12 changes: 12 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.147699414018-iqk5i6nmok3bc4pont6t4e0rpvtt8b0v</string>
</array>
</dict>
</array>

<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
Expand Down
9 changes: 3 additions & 6 deletions lib/presentation/history/history_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:timeago/timeago.dart' as timeago;
import 'package:training_app/presentation/exercise/exercise_page.dart';

import 'history_add_page.dart';

class HistoryPage extends StatelessWidget {
String _uid = '';
HistoryPage(uid) {
this._uid = uid;
}
final String _uid;
@override
HistoryPage(this._uid);

Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -57,7 +55,6 @@ class HistoryPage extends StatelessWidget {
.map(
(doc) => Card(
child: ListTile(
leading: Text('1'),
title: Text(doc['title']),
subtitle: Text(timeago.format(doc['date'].toDate())),
),
Expand Down
98 changes: 14 additions & 84 deletions lib/presentation/main/main.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'package:training_app/presentation/history/history_model.dart';
import 'package:training_app/presentation/signUp/sign_up_page.dart';

import '../../common_func.dart';
import 'package:training_app/signIn/sign_in_page.dart';

import '../app_page.dart';
import 'main_model.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
Expand All @@ -20,87 +16,21 @@ void main() async {
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final mailController = TextEditingController();
final passwordController = TextEditingController();
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData.dark(),
home: ChangeNotifierProvider<SignInModel>(
create: (_) => SignInModel(),
child: Scaffold(
appBar: AppBar(
title: Text('ログイン'),
),
body: Consumer<SignInModel>(
builder: (context, model, child) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
TextField(
decoration: InputDecoration(
hintText: '[email protected]',
),
obscureText: false,
controller: mailController,
onChanged: (text) {
model.mail = text;
},
),
TextField(
decoration: InputDecoration(
hintText: 'パスワード',
),
obscureText: true,
controller: passwordController,
onChanged: (text) {
model.password = text;
},
),
ElevatedButton(
child: Text('ログインする'),
onPressed: () async {
model.login(context);
},
),
ElevatedButton(
child: Text('新規登録'),
onPressed: () async {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SignUpPage()),
);
},
),
],
),
);
},
),
),
home: StreamBuilder(
stream: FirebaseAuth.instance.authStateChanges(),
builder: (context, AsyncSnapshot<User?> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(child: CircularProgressIndicator());
}
if (snapshot.hasData) {
return AppPage(snapshot.data!.uid);
}
return SignInPage();
},
),
);
}

Future? _showDialog(
BuildContext context,
String title,
) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(title),
actions: <Widget>[
ElevatedButton(
child: Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
}
18 changes: 18 additions & 0 deletions lib/presentation/profile/profile_page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart';

class ProfilePage extends StatelessWidget {
final GoogleSignIn _googleSignIn = GoogleSignIn();

Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
Expand All @@ -13,9 +17,23 @@ class ProfilePage extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('ProfilePage'),
ElevatedButton(
onPressed: () {
_handleSignOut().catchError((e) => print(e));
},
child: Text('Sign out'))
],
),
),
);
}

Future<void> _handleSignOut() async {
await FirebaseAuth.instance.signOut();
try {
await _googleSignIn.signOut();
} catch (e) {
print(e);
}
}
}
Loading

0 comments on commit d6bd44f

Please sign in to comment.