first commit
This commit is contained in:
49
lib/modules/preview/opacity_dialog.dart
Normal file
49
lib/modules/preview/opacity_dialog.dart
Normal file
@@ -0,0 +1,49 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class OpacityDialog extends StatefulWidget {
|
||||
final double initial;
|
||||
const OpacityDialog({super.key, required this.initial});
|
||||
@override
|
||||
_OpacityDialogState createState() => _OpacityDialogState();
|
||||
}
|
||||
|
||||
class _OpacityDialogState extends State<OpacityDialog> {
|
||||
late double val;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
val = widget.initial;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text('Opacity Watermark'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Slider(
|
||||
value: val,
|
||||
min: 0.1,
|
||||
max: 1.0,
|
||||
divisions: 9,
|
||||
label: '${(val * 100).toStringAsFixed(0)}%',
|
||||
onChanged: (v) => setState(() => val = v),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Text('Preview: ${(val * 100).toStringAsFixed(0)}%'),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text('Batal'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, val),
|
||||
child: Text('OK'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
103
lib/modules/preview/preview_screen.dart
Normal file
103
lib/modules/preview/preview_screen.dart
Normal file
@@ -0,0 +1,103 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:photobooth_mobile_app/core/image/image_cleanup_service.dart';
|
||||
import 'package:photobooth_mobile_app/core/image/image_compositor.dart';
|
||||
import 'package:photobooth_mobile_app/core/print/print_service.dart';
|
||||
|
||||
class PreviewScreen extends StatefulWidget {
|
||||
final String imagePath;
|
||||
final String frameAsset;
|
||||
final bool isFrontCamera;
|
||||
|
||||
const PreviewScreen({
|
||||
super.key,
|
||||
required this.imagePath,
|
||||
required this.frameAsset,
|
||||
required this.isFrontCamera,
|
||||
});
|
||||
|
||||
@override
|
||||
State<PreviewScreen> createState() => _PreviewScreenState();
|
||||
}
|
||||
|
||||
class _PreviewScreenState extends State<PreviewScreen> {
|
||||
final ImageCompositor _compositor = ImageCompositor();
|
||||
final PrintService _printer = PrintService();
|
||||
final ImageCleanupService _cleanup = ImageCleanupService();
|
||||
|
||||
late String _finalPath;
|
||||
String? _lastFinalPath;
|
||||
bool _loading = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_init();
|
||||
}
|
||||
|
||||
Future<void> _init() async {
|
||||
final dir = await getTemporaryDirectory();
|
||||
final twibbonData = await rootBundle.load(widget.frameAsset);
|
||||
|
||||
await _cleanup.deleteIfExists(_lastFinalPath);
|
||||
|
||||
final newPath = await _compositor.composeFinalA5(
|
||||
imagePath: widget.imagePath,
|
||||
twibbonBytes: twibbonData.buffer.asUint8List(),
|
||||
tempDir: dir.path,
|
||||
isFrontCamera: widget.isFrontCamera,
|
||||
);
|
||||
|
||||
_lastFinalPath = newPath;
|
||||
_finalPath = newPath;
|
||||
|
||||
await _cleanup.keepLastN(tempDir: dir.path, maxFiles: 10);
|
||||
|
||||
if (mounted) {
|
||||
setState(() => _loading = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_cleanup.deleteIfExists(_finalPath);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Pratinjau')),
|
||||
body: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _loading
|
||||
? const Center(child: CupertinoActivityIndicator())
|
||||
: Center(
|
||||
child: AspectRatio(
|
||||
aspectRatio: 148 / 210,
|
||||
child: Image.file(File(_finalPath), fit: BoxFit.contain),
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: ElevatedButton.icon(
|
||||
icon: const Icon(Icons.print),
|
||||
label: Text(_loading ? 'Menyiapkan...' : 'Cetak'),
|
||||
onPressed: _loading
|
||||
? null
|
||||
: () async {
|
||||
final pdfPath = await _printer.generateA5Pdf(_finalPath);
|
||||
await _printer.sharePdf(pdfPath);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user