撤销功能

This commit is contained in:
toly
2023-05-14 09:43:11 +08:00
parent c39db01b01
commit fe6f3d530d
2 changed files with 64 additions and 1 deletions

View File

@@ -33,7 +33,6 @@ class _PaperState extends State<Paper> {
Colors.indigo,
Colors.purple,
Colors.pink,
Colors.grey,
Colors.redAccent,
Colors.orangeAccent,
@@ -48,11 +47,27 @@ class _PaperState extends State<Paper> {
// 支持的线粗
final List<double> supportStorkWidths = [1, 2, 4, 6, 8, 10];
List<Line> _historyLines = [];
void _back() {
Line line = _lines.removeLast();
_historyLines.add(line);
setState(() {});
}
void _revocation() {
Line line = _historyLines.removeLast();
_lines.add(line);
setState(() {});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: PaperAppBar(
onClear: _showClearDialog,
onBack: _lines.isEmpty ? null : _back,
onRevocation: _historyLines.isEmpty ? null : _revocation,
),
body: Stack(
children: [

View File

@@ -4,10 +4,14 @@ import 'package:flutter/services.dart';
class PaperAppBar extends StatelessWidget implements PreferredSizeWidget {
final VoidCallback onClear;
final VoidCallback? onBack;
final VoidCallback? onRevocation;
const PaperAppBar({
Key? key,
required this.onClear,
this.onBack,
this.onRevocation,
}) : super(key: key);
@override
@@ -19,6 +23,11 @@ class PaperAppBar extends StatelessWidget implements PreferredSizeWidget {
statusBarIconBrightness: Brightness.dark,
statusBarColor: Colors.transparent),
backgroundColor: Colors.white,
leading: BackUpButtons(
onBack: onBack,
onRevocation: onRevocation,
),
leadingWidth: 100,
title: Text(
'画板绘制',
style: TextStyle(color: Colors.black, fontSize: 16),
@@ -39,3 +48,42 @@ class PaperAppBar extends StatelessWidget implements PreferredSizeWidget {
@override
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
}
class BackUpButtons extends StatelessWidget {
final VoidCallback? onBack;
final VoidCallback? onRevocation;
const BackUpButtons({
Key? key,
required this.onBack,
required this.onRevocation,
}) : super(key: key);
@override
Widget build(BuildContext context) {
const BoxConstraints cts = BoxConstraints(minHeight: 32, minWidth: 32);
Color backColor = onBack ==null?Colors.grey:Colors.black;
Color revocationColor = onRevocation ==null?Colors.grey:Colors.black;
return Center(
child: Wrap(
children: [
Transform.scale(
scaleX: -1,
child: IconButton(
splashRadius: 20,
constraints: cts,
onPressed: onBack,
icon: Icon(Icons.next_plan_outlined,color: backColor),
),
),
IconButton(
splashRadius: 20,
onPressed: onRevocation,
constraints: cts,
icon: Icon(Icons.next_plan_outlined, color: revocationColor),
)
],
),
);
}
}