-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AlertDialogのUI実装 #19
base: develop
Are you sure you want to change the base?
AlertDialogのUI実装 #19
Changes from 9 commits
3862d07
94a823d
fea759b
82bcfe2
afad10e
45cc89d
5b45608
f986580
054bb62
49bb4a7
c991d8e
d29fed3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
buildscript { | ||
ext.kotlin_version = '1.7.10' | ||
ext.kotlin_version = '1.9.0' | ||
repositories { | ||
google() | ||
mavenCentral() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:pg_mobile/util/navigator_util.dart'; | ||
|
||
class DebugAlertDialogPage extends StatelessWidget { | ||
const DebugAlertDialogPage({Key? key}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Alert Dialog'), | ||
), | ||
body: SafeArea( | ||
child: Center( | ||
child: ElevatedButton( | ||
onPressed: () { | ||
NavigatorUtil.showCommonAlertDialog( | ||
context, | ||
titleText: 'titleText', | ||
contentText: 'contentText', | ||
onPressedCancel: () { | ||
Navigator.pop(context); | ||
}, | ||
onPressedOK: () { | ||
Navigator.pop(context); | ||
}, | ||
); | ||
}, | ||
child: const Text('AlertDialogを表示'), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_screenutil/flutter_screenutil.dart'; | ||
import 'package:pg_mobile/debug/debug_alert_dialog_page.dart'; | ||
import 'package:pg_mobile/debug/debug_text_theme_page.dart'; | ||
import 'package:pg_mobile/debug/login_sample/login_sample.dart'; | ||
|
||
|
@@ -50,6 +51,16 @@ class DebugPage extends StatelessWidget { | |
); | ||
}, | ||
), | ||
_button( | ||
'Alert Dialog', | ||
onPressed: () { | ||
Navigator.of(context).push( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pushだけUtilのメソッドに変更して欲しい🙏 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 修正しやす🙆♂️ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. d29fed3 |
||
MaterialPageRoute( | ||
builder: (context) => const DebugAlertDialogPage(), | ||
), | ||
); | ||
}, | ||
), | ||
], | ||
), | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
extension TargetPlatformExtension on TargetPlatform { | ||
bool get isIOS => this == TargetPlatform.iOS; | ||
bool get isAndroid => this == TargetPlatform.android; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:pg_mobile/extensions/target_platform_extension.dart'; | ||
import 'package:pg_mobile/widgets/common_cupertino_alert_dialog.dart'; | ||
import 'package:pg_mobile/widgets/common_material_alert_dialog.dart'; | ||
|
||
class NavigatorUtil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. この名前だとrooting系の処理まとまってるクラスなのかなーって思ってしまうから There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 確かにそうやね… There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. c991d8e |
||
/// OSに応じたAlertDialogを表示するメソッド | ||
static void showCommonAlertDialog( | ||
BuildContext context, { | ||
required String titleText, | ||
required String contentText, | ||
String cancelText = 'キャンセル', | ||
String okText = 'OK', | ||
required void Function()? onPressedCancel, | ||
required void Function()? onPressedOK, | ||
bool hideCancel = false, | ||
}) { | ||
if (Theme.of(context).platform.isIOS) { | ||
showCupertinoModalPopup<void>( | ||
context: context, | ||
builder: (BuildContext context) => CommonCupertinoAlertDialog( | ||
titleText: titleText, | ||
contentText: contentText, | ||
cancelText: cancelText, | ||
okText: okText, | ||
onPressedCancel: onPressedCancel, | ||
onPressedOK: onPressedOK, | ||
hideCancel: hideCancel, | ||
), | ||
); | ||
} else { | ||
showDialog<void>( | ||
context: context, | ||
builder: (BuildContext context) { | ||
return CommonMaterialAlertDialog( | ||
titleText: titleText, | ||
contentText: contentText, | ||
cancelText: cancelText, | ||
okText: okText, | ||
onPressedCancel: onPressedCancel, | ||
onPressedOK: onPressedOK, | ||
hideCancel: hideCancel, | ||
); | ||
}, | ||
); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import 'package:flutter/cupertino.dart'; | ||
|
||
class CommonCupertinoAlertDialog extends StatelessWidget { | ||
const CommonCupertinoAlertDialog({ | ||
Key? key, | ||
required this.titleText, | ||
required this.contentText, | ||
required this.cancelText, | ||
required this.okText, | ||
required this.onPressedCancel, | ||
required this.onPressedOK, | ||
required this.hideCancel, | ||
}) : super(key: key); | ||
|
||
final String titleText; | ||
final String contentText; | ||
final String cancelText; | ||
final String okText; | ||
final void Function()? onPressedCancel; | ||
final void Function()? onPressedOK; | ||
final bool hideCancel; | ||
|
||
static const TextStyle _actionsTextStyle = TextStyle( | ||
color: CupertinoColors.systemBlue, | ||
); | ||
|
||
bool get _showCancel => !hideCancel; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return CupertinoAlertDialog( | ||
title: Text(titleText), | ||
content: Text(contentText), | ||
actions: <CupertinoDialogAction>[ | ||
if (_showCancel) | ||
CupertinoDialogAction( | ||
onPressed: onPressedCancel, | ||
textStyle: _actionsTextStyle, | ||
child: Text(cancelText), | ||
), | ||
CupertinoDialogAction( | ||
isDestructiveAction: true, | ||
onPressed: onPressedOK, | ||
textStyle: _actionsTextStyle, | ||
child: Text(okText), | ||
), | ||
], | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:pg_mobile/constants/app_colors.dart'; | ||
|
||
class CommonMaterialAlertDialog extends StatelessWidget { | ||
const CommonMaterialAlertDialog({ | ||
Key? key, | ||
required this.titleText, | ||
required this.contentText, | ||
required this.cancelText, | ||
required this.okText, | ||
required this.onPressedCancel, | ||
required this.onPressedOK, | ||
required this.hideCancel, | ||
}) : super(key: key); | ||
|
||
final String titleText; | ||
final String contentText; | ||
final String cancelText; | ||
final String okText; | ||
final void Function()? onPressedCancel; | ||
final void Function()? onPressedOK; | ||
final bool hideCancel; | ||
|
||
bool get _showCancel => !hideCancel; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return AlertDialog( | ||
title: Text( | ||
titleText, | ||
style: const TextStyle(color: AppColors.black), | ||
), | ||
content: Text( | ||
contentText, | ||
style: const TextStyle(color: AppColors.black), | ||
), | ||
actions: <Widget>[ | ||
if (_showCancel) | ||
TextButton( | ||
onPressed: onPressedCancel, | ||
child: Text(cancelText), | ||
), | ||
TextButton( | ||
onPressed: onPressedOK, | ||
child: Text(okText), | ||
), | ||
], | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
このコードってどこかで使用される予定とか将来的にあったりする?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Figmaにはまだ書いてないけどログアウトとか権限周りで使うよ