Skip to content

Commit

Permalink
refactor: add delete dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
SungyeopJeong authored and sboh1214 committed Aug 16, 2023
1 parent c142f93 commit b3d8940
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 74 deletions.
84 changes: 10 additions & 74 deletions lib/pages/timetable_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:otlplus/utils/build_page_route.dart';
import 'package:otlplus/providers/lecture_search_model.dart';
import 'package:otlplus/utils/responsive_button.dart';
import 'package:otlplus/widgets/delete_dialog.dart';
import 'package:otlplus/widgets/lecture_search.dart';
import 'package:otlplus/widgets/map_view.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -254,8 +255,15 @@ class _TimetablePageState extends State<TimetablePage> {
barrierDismissible: true,
barrierLabel:
MaterialLocalizations.of(context).modalBarrierDismissLabel,
pageBuilder: (context, _, __) =>
_buildDeleteDialog(context, timetableModel.selectedIndex),
pageBuilder: (context, _, __) => DeleteDialog(
text: 'timetable.ask_delete_tab'.tr(args: [
'timetable.tab'
.tr(args: [timetableModel.selectedIndex.toString()])
]),
onDelete: () {
context.read<TimetableModel>().deleteTimetable();
},
),
);
},
onExportTap: (type) {
Expand All @@ -265,76 +273,4 @@ class _TimetablePageState extends State<TimetablePage> {
},
);
}

Widget _buildDeleteDialog(BuildContext context, int i) {
return Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Material(
child: IntrinsicWidth(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
padding: const EdgeInsets.fromLTRB(16, 19, 16, 20),
alignment: Alignment.center,
color: Colors.white,
child: Text(
'timetable.ask_delete_tab'.tr(args: [
'timetable.tab'.tr(args: [i.toString()])
]),
style: TextStyle(
fontSize: 12,
),
),
),
Row(
children: [
Expanded(
child: GestureDetector(
onTap: () => Navigator.pop(context),
child: Container(
height: 40,
alignment: Alignment.center,
color: OTLColor.grayE,
child: Text(
'common.cancel'.tr(),
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w700,
),
),
),
),
),
Expanded(
child: GestureDetector(
onTap: () {
context.read<TimetableModel>().deleteTimetable();
Navigator.pop(context);
},
child: Container(
height: 40,
alignment: Alignment.center,
color: OTLColor.pinksMain,
child: Text(
'common.delete'.tr(),
style: TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.w700,
),
),
),
),
),
],
)
],
),
),
),
),
);
}
}
83 changes: 83 additions & 0 deletions lib/widgets/delete_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:otlplus/constants/color.dart';

class DeleteDialog extends StatelessWidget {
const DeleteDialog({Key? key, required this.text, this.onDelete})
: super(key: key);
final String text;
final void Function()? onDelete;

@override
Widget build(BuildContext context) {
return Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Material(
child: IntrinsicWidth(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
padding: const EdgeInsets.fromLTRB(16, 19, 16, 20),
alignment: Alignment.center,
color: Colors.white,
child: Text(
text,
style: TextStyle(
fontSize: 12,
),
),
),
Row(
children: [
_buildButton(
() => Navigator.pop(context),
text: 'common.cancel'.tr(),
buttonColor: OTLColor.grayE,
),
_buildButton(
() {
if (onDelete != null) onDelete!();
Navigator.pop(context);
},
text: 'common.delete'.tr(),
buttonColor: OTLColor.pinksMain,
textColor: Colors.white,
),
],
)
],
),
),
),
),
);
}

Widget _buildButton(
void Function()? onTap, {
required String text,
required Color buttonColor,
Color? textColor,
}) {
return Expanded(
child: GestureDetector(
onTap: onTap,
child: Container(
height: 40,
alignment: Alignment.center,
color: buttonColor,
child: Text(
text,
style: TextStyle(
color: textColor,
fontSize: 12,
fontWeight: FontWeight.w700,
),
),
),
),
);
}
}

0 comments on commit b3d8940

Please sign in to comment.