Skip to content

Commit

Permalink
[timetable] take screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
liplum committed Sep 25, 2024
1 parent 965dbd8 commit 8e4eb29
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 54 deletions.
96 changes: 46 additions & 50 deletions lib/timetable/page/screenshot.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:mimir/design/widget/task_builder.dart';
import 'package:rettulf/rettulf.dart';
import 'package:mimir/design/adaptive/foundation.dart';
import 'package:mimir/settings/settings.dart';
import 'package:mimir/utils/screenshot.dart';

Expand All @@ -18,23 +18,23 @@ typedef TimetableScreenshotConfig = ({
bool enableBackground,
});

class TimetableScreenshotConfigEditor extends StatefulWidget {
class TimetableScreenshotPage extends StatefulWidget {
final TimetableEntity timetable;
final bool initialGrayOutTakenLessons;
final int weekIndex;

const TimetableScreenshotConfigEditor({
const TimetableScreenshotPage({
super.key,
required this.timetable,
this.initialGrayOutTakenLessons = false,
required this.weekIndex,
});

@override
State<TimetableScreenshotConfigEditor> createState() => _TimetableScreenshotConfigEditorState();
State<TimetableScreenshotPage> createState() => _TimetableScreenshotPageState();
}

class _TimetableScreenshotConfigEditorState extends State<TimetableScreenshotConfigEditor> {
class _TimetableScreenshotPageState extends State<TimetableScreenshotPage> {
late final $signature = TextEditingController(text: widget.timetable.signature);
late bool grayOutTakenLessons = widget.initialGrayOutTakenLessons;
late bool grayOutTakenLessons = Settings.timetable.cellStyle?.grayOutTakenLessons ?? false;
var enableBackground = true;

@override
Expand Down Expand Up @@ -65,19 +65,48 @@ class _TimetableScreenshotConfigEditorState extends State<TimetableScreenshotCon
}

Widget buildScreenshotAction() {
return PlatformTextButton(
child: i18n.screenshot.take.text(),
onPressed: () async {
Settings.lastSignature = $signature.text;
context.pop<TimetableScreenshotConfig>((
signature: $signature.text.trim(),
grayOutTakenLessons: grayOutTakenLessons == true,
enableBackground: enableBackground,
));
return TaskBuilder(
task: takeScreenshot,
builder: (context, task, running) {
return PlatformTextButton(
onPressed: task,
child: i18n.screenshot.take.text(),
);
},
);
}

Future<void> takeScreenshot() async {
final weekIndex = widget.weekIndex;
final timetable = widget.timetable;
final config = (
signature: $signature.text.trim(),
grayOutTakenLessons: grayOutTakenLessons == true,
enableBackground: enableBackground,
);
Settings.lastSignature = $signature.text;
final fi = await takeWidgetScreenshot(
context: context,
name: 'timetable.png',
child: Builder(
builder: (ctx) => Material(
child: TimetableStyleProv(
child: TimetableWeeklyScreenshotFilm(
config: config,
timetable: timetable,
weekIndex: weekIndex,
fullSize: ctx.mediaQuery.size,
),
),
),
),
);

await onScreenshotTaken(fi.path);
if (!mounted) return;
context.pop();
}

Widget buildSignatureInput() {
return ListTile(
isThreeLine: true,
Expand Down Expand Up @@ -177,36 +206,3 @@ class TimetableWeeklyScreenshotFilm extends StatelessWidget {
return week;
}
}

Future<void> takeTimetableScreenshot({
required BuildContext context,
required TimetableEntity timetable,
required int weekIndex,
}) async {
final config = await context.showSheet<TimetableScreenshotConfig>(
(ctx) => TimetableScreenshotConfigEditor(
timetable: timetable,
initialGrayOutTakenLessons: Settings.timetable.cellStyle?.grayOutTakenLessons ?? false,
),
);
if (config == null) return;
if (!context.mounted) return;
final fi = await takeWidgetScreenshot(
context: context,
name: 'timetable.png',
child: Builder(
builder: (ctx) => Material(
child: TimetableStyleProv(
child: TimetableWeeklyScreenshotFilm(
config: config,
timetable: timetable,
weekIndex: weekIndex,
fullSize: ctx.mediaQuery.size,
),
),
),
),
);

await onScreenshotTaken(fi.path);
}
10 changes: 6 additions & 4 deletions lib/timetable/page/timetable.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:mimir/design/adaptive/foundation.dart';
import 'package:mimir/design/adaptive/menu.dart';
import 'package:mimir/design/animation/progress.dart';
import 'package:mimir/design/widget/fab.dart';
Expand Down Expand Up @@ -145,10 +146,11 @@ class _TimetableBoardPageState extends ConsumerState<TimetableBoardPage> {
icon: Icons.screenshot,
title: i18n.screenshot.screenshot,
onTap: () async {
await takeTimetableScreenshot(
context: context,
timetable: timetable,
weekIndex: $currentPos.value.weekIndex,
await context.showSheet(
(ctx) => TimetableScreenshotPage(
timetable: timetable,
weekIndex: $currentPos.value.weekIndex,
),
);
},
),
Expand Down

0 comments on commit 8e4eb29

Please sign in to comment.