撤销功能
This commit is contained in:
@@ -33,7 +33,6 @@ class _PaperState extends State<Paper> {
|
|||||||
Colors.indigo,
|
Colors.indigo,
|
||||||
Colors.purple,
|
Colors.purple,
|
||||||
Colors.pink,
|
Colors.pink,
|
||||||
|
|
||||||
Colors.grey,
|
Colors.grey,
|
||||||
Colors.redAccent,
|
Colors.redAccent,
|
||||||
Colors.orangeAccent,
|
Colors.orangeAccent,
|
||||||
@@ -48,11 +47,27 @@ class _PaperState extends State<Paper> {
|
|||||||
// 支持的线粗
|
// 支持的线粗
|
||||||
final List<double> supportStorkWidths = [1, 2, 4, 6, 8, 10];
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: PaperAppBar(
|
appBar: PaperAppBar(
|
||||||
onClear: _showClearDialog,
|
onClear: _showClearDialog,
|
||||||
|
onBack: _lines.isEmpty ? null : _back,
|
||||||
|
onRevocation: _historyLines.isEmpty ? null : _revocation,
|
||||||
),
|
),
|
||||||
body: Stack(
|
body: Stack(
|
||||||
children: [
|
children: [
|
||||||
|
|||||||
@@ -4,10 +4,14 @@ import 'package:flutter/services.dart';
|
|||||||
|
|
||||||
class PaperAppBar extends StatelessWidget implements PreferredSizeWidget {
|
class PaperAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||||
final VoidCallback onClear;
|
final VoidCallback onClear;
|
||||||
|
final VoidCallback? onBack;
|
||||||
|
final VoidCallback? onRevocation;
|
||||||
|
|
||||||
const PaperAppBar({
|
const PaperAppBar({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.onClear,
|
required this.onClear,
|
||||||
|
this.onBack,
|
||||||
|
this.onRevocation,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -19,6 +23,11 @@ class PaperAppBar extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
statusBarIconBrightness: Brightness.dark,
|
statusBarIconBrightness: Brightness.dark,
|
||||||
statusBarColor: Colors.transparent),
|
statusBarColor: Colors.transparent),
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
|
leading: BackUpButtons(
|
||||||
|
onBack: onBack,
|
||||||
|
onRevocation: onRevocation,
|
||||||
|
),
|
||||||
|
leadingWidth: 100,
|
||||||
title: Text(
|
title: Text(
|
||||||
'画板绘制',
|
'画板绘制',
|
||||||
style: TextStyle(color: Colors.black, fontSize: 16),
|
style: TextStyle(color: Colors.black, fontSize: 16),
|
||||||
@@ -39,3 +48,42 @@ class PaperAppBar extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
@override
|
@override
|
||||||
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
|
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),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user