forked from firka/firka
refactor: extract showLessonBottomSheet out to a file
This commit is contained in:
167
firka/lib/helpers/ui/common_bottom_sheets.dart
Normal file
167
firka/lib/helpers/ui/common_bottom_sheets.dart
Normal file
@@ -0,0 +1,167 @@
|
||||
import 'package:firka/helpers/extensions.dart';
|
||||
import 'package:firka/helpers/settings/setting.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
|
||||
import '../../main.dart';
|
||||
import '../../ui/model/style.dart';
|
||||
import '../../ui/widget/class_icon.dart';
|
||||
import '../api/model/timetable.dart';
|
||||
import 'firka_card.dart';
|
||||
|
||||
Future<void> showLessonBottomSheet(
|
||||
BuildContext context,
|
||||
AppInitialization data,
|
||||
Lesson lesson,
|
||||
int? lessonNo,
|
||||
Color accent,
|
||||
Color secondary,
|
||||
Color bgColor) async {
|
||||
final statsForNerdsEnabled = data.settings
|
||||
.group("settings")
|
||||
.subGroup("developer")
|
||||
.boolean("stats_for_nerds");
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
elevation: 100,
|
||||
isScrollControlled: true,
|
||||
enableDrag: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
barrierColor: appStyle.colors.a15p,
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: MediaQuery.of(context).size.height *
|
||||
(statsForNerdsEnabled ? 0.35 : 0.3),
|
||||
),
|
||||
builder: (BuildContext context) {
|
||||
Widget statsForNerds = SizedBox();
|
||||
|
||||
final y2k = DateTime(2000, 1);
|
||||
|
||||
if (statsForNerdsEnabled) {
|
||||
final stats =
|
||||
"${data.l10n.stats_date}: ${lesson.start.isAfter(y2k) ? lesson.start.format(data.l10n, FormatMode.yyyymmddhhmmss) : "N/A"}\n"
|
||||
"${data.l10n.stats_created_at}: ${lesson.createdAt.isAfter(y2k) ? lesson.createdAt.format(data.l10n, FormatMode.yyyymmddhhmmss) : "N/A"}\n"
|
||||
"${data.l10n.stats_last_mod}: ${lesson.lastModifiedAt.isAfter(y2k) ? lesson.lastModifiedAt.format(data.l10n, FormatMode.yyyymmddhhmmss) : "N/A"}";
|
||||
statsForNerds = Text(stats,
|
||||
style:
|
||||
appStyle.fonts.B_16R.apply(color: appStyle.colors.textPrimary));
|
||||
}
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: GestureDetector(
|
||||
onTap: () => Navigator.pop(context),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(color: Colors.transparent),
|
||||
),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: appStyle.colors.background,
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: Stack(
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
"assets/icons/subtract.svg",
|
||||
color: bgColor,
|
||||
width: 18,
|
||||
height: 18,
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 5),
|
||||
child: Text(lessonNo.toString(),
|
||||
style: appStyle.fonts.B_12R
|
||||
.apply(color: secondary)),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
Transform.translate(
|
||||
offset: Offset(-4, 0),
|
||||
child: Card(
|
||||
shadowColor: Colors.transparent,
|
||||
color: bgColor,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16)),
|
||||
child: Padding(
|
||||
padding: EdgeInsetsGeometry.all(4),
|
||||
child: ClassIconWidget(
|
||||
color: accent,
|
||||
size: 20,
|
||||
uid: lesson.uid,
|
||||
className: lesson.name,
|
||||
category: lesson.subject?.name ?? '',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 6),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"${lesson.name} ${statsForNerdsEnabled ? "(${lesson.classGroup?.name ?? ''})" : ""}",
|
||||
style: appStyle.fonts.H_18px
|
||||
.apply(color: appStyle.colors.textPrimary),
|
||||
),
|
||||
Text(
|
||||
lesson.teacher ?? 'N/A',
|
||||
style: appStyle.fonts.B_14R
|
||||
.apply(color: appStyle.colors.textPrimary),
|
||||
),
|
||||
Text(
|
||||
'${lesson.start.format(data.l10n, FormatMode.hmm)} - ${lesson.end.format(data.l10n, FormatMode.hmm)}',
|
||||
style: appStyle.fonts.B_14R
|
||||
.apply(color: appStyle.colors.textPrimary),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
FirkaCard(left: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
data.l10n.lesson_subject,
|
||||
style: appStyle.fonts.H_14px
|
||||
.apply(color: appStyle.colors.textPrimary),
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
Text(
|
||||
lesson.theme ?? 'N/A',
|
||||
style: appStyle.fonts.B_16R
|
||||
.apply(color: appStyle.colors.textPrimary),
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
statsForNerds
|
||||
],
|
||||
)
|
||||
])
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||
import '../../../helpers/api/model/test.dart';
|
||||
import '../../../helpers/api/model/timetable.dart';
|
||||
import '../../../helpers/debug_helper.dart';
|
||||
import '../../../helpers/ui/common_bottom_sheets.dart';
|
||||
import '../../widget/class_icon.dart';
|
||||
import '../../widget/firka_icon.dart';
|
||||
import 'bubble_test.dart';
|
||||
@@ -336,160 +337,3 @@ class LessonWidget extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void showLessonBottomSheet(
|
||||
BuildContext context,
|
||||
AppInitialization data,
|
||||
Lesson lesson,
|
||||
int? lessonNo,
|
||||
Color accent,
|
||||
Color secondary,
|
||||
Color bgColor) {
|
||||
final statsForNerdsEnabled = data.settings
|
||||
.group("settings")
|
||||
.subGroup("developer")
|
||||
.boolean("stats_for_nerds");
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
elevation: 100,
|
||||
isScrollControlled: true,
|
||||
enableDrag: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
barrierColor: appStyle.colors.a15p,
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: MediaQuery.of(context).size.height *
|
||||
(statsForNerdsEnabled ? 0.35 : 0.3),
|
||||
),
|
||||
builder: (BuildContext context) {
|
||||
Widget statsForNerds = SizedBox();
|
||||
|
||||
final y2k = DateTime(2000, 1);
|
||||
|
||||
if (statsForNerdsEnabled) {
|
||||
final stats =
|
||||
"${data.l10n.stats_date}: ${lesson.start.isAfter(y2k) ? lesson.start.format(data.l10n, FormatMode.yyyymmddhhmmss) : "N/A"}\n"
|
||||
"${data.l10n.stats_created_at}: ${lesson.createdAt.isAfter(y2k) ? lesson.createdAt.format(data.l10n, FormatMode.yyyymmddhhmmss) : "N/A"}\n"
|
||||
"${data.l10n.stats_last_mod}: ${lesson.lastModifiedAt.isAfter(y2k) ? lesson.lastModifiedAt.format(data.l10n, FormatMode.yyyymmddhhmmss) : "N/A"}";
|
||||
statsForNerds = Text(stats,
|
||||
style:
|
||||
appStyle.fonts.B_16R.apply(color: appStyle.colors.textPrimary));
|
||||
}
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: GestureDetector(
|
||||
onTap: () => Navigator.pop(context),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(color: Colors.transparent),
|
||||
),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: appStyle.colors.background,
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: Stack(
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
"assets/icons/subtract.svg",
|
||||
color: bgColor,
|
||||
width: 18,
|
||||
height: 18,
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 5),
|
||||
child: Text(lessonNo.toString(),
|
||||
style: appStyle.fonts.B_12R
|
||||
.apply(color: secondary)),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
Transform.translate(
|
||||
offset: Offset(-4, 0),
|
||||
child: Card(
|
||||
shadowColor: Colors.transparent,
|
||||
color: bgColor,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16)),
|
||||
child: Padding(
|
||||
padding: EdgeInsetsGeometry.all(4),
|
||||
child: ClassIconWidget(
|
||||
color: accent,
|
||||
size: 20,
|
||||
uid: lesson.uid,
|
||||
className: lesson.name,
|
||||
category: lesson.subject?.name ?? '',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 6),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"${lesson.name} ${statsForNerdsEnabled ? "(${lesson.classGroup?.name ?? ''})" : ""}",
|
||||
style: appStyle.fonts.H_18px
|
||||
.apply(color: appStyle.colors.textPrimary),
|
||||
),
|
||||
Text(
|
||||
lesson.teacher ?? 'N/A',
|
||||
style: appStyle.fonts.B_14R
|
||||
.apply(color: appStyle.colors.textPrimary),
|
||||
),
|
||||
Text(
|
||||
'${lesson.start.format(data.l10n, FormatMode.hmm)} - ${lesson.end.format(data.l10n, FormatMode.hmm)}',
|
||||
style: appStyle.fonts.B_14R
|
||||
.apply(color: appStyle.colors.textPrimary),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
FirkaCard(left: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
data.l10n.lesson_subject,
|
||||
style: appStyle.fonts.H_14px
|
||||
.apply(color: appStyle.colors.textPrimary),
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
Text(
|
||||
lesson.theme ?? 'N/A',
|
||||
style: appStyle.fonts.B_16R
|
||||
.apply(color: appStyle.colors.textPrimary),
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
statsForNerds
|
||||
],
|
||||
)
|
||||
])
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user