Skip to content

Commit

Permalink
[add]帖子截图加底边栏
Browse files Browse the repository at this point in the history
  • Loading branch information
hxphieno committed Mar 15, 2024
1 parent f72a833 commit cd8b046
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 43 deletions.
Binary file added assets/images/bottom_bar_black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/bottom_bar_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 37 additions & 12 deletions lib/feedback/view/post_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:flutter_svg/svg.dart';
import 'package:gallery_saver/gallery_saver.dart';
import 'package:image_picker/image_picker.dart';
import 'package:path/path.dart' as path;
import 'dart:ui' as ui;
import 'package:provider/provider.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:screenshot/screenshot.dart';
Expand All @@ -33,6 +34,7 @@ import 'package:wechat_assets_picker/wechat_assets_picker.dart';
import '../../commons/themes/template/wpy_theme_data.dart';
import '../../commons/themes/wpy_theme.dart';
import '../../commons/widgets/w_button.dart';
import '../../schedule/page/course_page.dart';
import 'components/official_comment_card.dart';
import 'components/post_card.dart';
import 'lake_home_page/lake_notifier.dart';
Expand Down Expand Up @@ -281,17 +283,42 @@ class _PostDetailPageState extends State<PostDetailPage>

Future<void> takeScreenshot(
ScreenshotController _controller,
String name,
// String name,
// Widget? widget,
) async {
ToastProvider.running("生成截图中");
final dir = StorageUtil.tempDir.path;
final fullPath = path.join(dir, name);
await _controller.captureAndSave(dir,
fileName: name, delay: Duration(seconds: 1));
await GallerySaver.saveImage(fullPath, albumName: "微北洋");
await File(fullPath).delete();
ToastProvider.success("图片保存成功");
ui.Image? image=await _controller.captureAsUiImage(pixelRatio: 4.0);
double? photoWidth = image?.width.toDouble();
print(photoWidth);
await _controller.captureFromLongWidget(
Column(
children: [
Container(
width: photoWidth,
height: image?.height.toDouble(),
child: CustomPaint(

painter: CustomImagePainter(image!),
),
),
Container(
width: photoWidth,
height: photoWidth! * 1220 / 5892,
child: Image.asset(
WpyTheme.of(context).brightness == Brightness.dark
? "assets/images/bottom_bar_black.png"
: "assets/images/bottom_bar_white.png",
fit: BoxFit.fitWidth,
),
)
],
)).then((value) async {
final fullPath = await saveImageToPath(value);
GallerySaver.saveImage(fullPath!, albumName: "微北洋");
ToastProvider.success("图片保存成功");
}
);

}

@override
Expand Down Expand Up @@ -828,8 +855,7 @@ class _PostDetailPageState extends State<PostDetailPage>
),
CupertinoActionSheetAction(
onPressed: () async {
await takeScreenshot(screenshotController,
"wpy_post_${widget.post.id}_${DateTime.now().millisecondsSinceEpoch}.png");
await takeScreenshot(screenshotController);
Navigator.pop(context);
},
child: Text(
Expand Down Expand Up @@ -934,8 +960,7 @@ class _PostDetailPageState extends State<PostDetailPage>
onPressed: () async {
screenshotSelecting.value = false;
screenshotting.value = true;
await takeScreenshot(selectedScreenshotController,
"wpy_post_${widget.post.id}_${DateTime.now().millisecondsSinceEpoch}.png");
await takeScreenshot(selectedScreenshotController);
screenshotting.value = false;
screenshotList.empty();
},
Expand Down
58 changes: 27 additions & 31 deletions lib/schedule/page/course_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,38 +75,34 @@ class _CoursePageState extends State<CoursePage> {
ToastProvider.running("生成截图中");
screenshotController.captureAsUiImage(pixelRatio: 4.0).then((image) async {
await screenshotController
.captureFromLongWidget(Container(
width: image?.width.toDouble(),
height: image?.height.toDouble(),
child: Stack(
children: [
Container(
width: image?.width.toDouble(),
height: image?.height.toDouble(),
child: CustomPaint(
painter: ScheduleBackgroundPrinter(
primaryActionColor:
WpyTheme.of(context).get(WpyColorKey.primaryActionColor),
primaryLightActionColor: WpyTheme.of(context)
.get(WpyColorKey.primaryLightActionColor),
primaryBackgroundColor: WpyTheme.of(context)
.get(WpyColorKey.primaryBackgroundColor),
primaryLighterActionColor: WpyTheme.of(context)
.get(WpyColorKey.primaryLighterActionColor),
primaryLightestActionColor: WpyTheme.of(context)
.get(WpyColorKey.primaryLightestActionColor),
.captureFromLongWidget(Stack(
children: [
Container(
width: image?.width.toDouble(),
height: image?.height.toDouble(),
child: CustomPaint(
painter: ScheduleBackgroundPrinter(
primaryActionColor:
WpyTheme.of(context).get(WpyColorKey.primaryActionColor),
primaryLightActionColor: WpyTheme.of(context)
.get(WpyColorKey.primaryLightActionColor),
primaryBackgroundColor: WpyTheme.of(context)
.get(WpyColorKey.primaryBackgroundColor),
primaryLighterActionColor: WpyTheme.of(context)
.get(WpyColorKey.primaryLighterActionColor),
primaryLightestActionColor: WpyTheme.of(context)
.get(WpyColorKey.primaryLightestActionColor),
),
),
),
),
Container(
margin: EdgeInsets.symmetric(vertical: 10.r),
child: CustomPaint(
painter: CustomImagePainter(image!),
),
)
],
),
))
Container(
margin: EdgeInsets.symmetric(vertical: 10.r),
child: CustomPaint(
painter: CustomImagePainter(image!),
),
)
],
))
.then((value) async {
final fullPath = await saveImageToPath(value);
GallerySaver.saveImage(fullPath!, albumName: "微北洋");
Expand Down Expand Up @@ -372,7 +368,7 @@ Future<String?> saveImageToPath(Uint8List imageData) async {
try {
final directory = await getTemporaryDirectory();
final file = File(
"${directory.path}/schedule_${DateTime.now().millisecondsSinceEpoch}.png");
"${directory.path}/wpy_screenshot_${DateTime.now().millisecondsSinceEpoch}.png");
await file.writeAsBytes(imageData);
return file.path;
} catch (e) {
Expand Down

0 comments on commit cd8b046

Please sign in to comment.