From fe6f3d530dc4d84769a18f738c09f9432345ed2b Mon Sep 17 00:00:00 2001 From: toly <1981462002@qq.com> Date: Sun, 14 May 2023 09:43:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=92=A4=E9=94=80=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/paper/paper.dart | 17 ++++++++++++- lib/paper/paper_app_bar.dart | 48 ++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/lib/paper/paper.dart b/lib/paper/paper.dart index 6b2fb6b..4485c36 100644 --- a/lib/paper/paper.dart +++ b/lib/paper/paper.dart @@ -33,7 +33,6 @@ class _PaperState extends State { Colors.indigo, Colors.purple, Colors.pink, - Colors.grey, Colors.redAccent, Colors.orangeAccent, @@ -48,11 +47,27 @@ class _PaperState extends State { // 支持的线粗 final List supportStorkWidths = [1, 2, 4, 6, 8, 10]; + List _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: [ diff --git a/lib/paper/paper_app_bar.dart b/lib/paper/paper_app_bar.dart index 0aea897..92e6cfb 100644 --- a/lib/paper/paper_app_bar.dart +++ b/lib/paper/paper_app_bar.dart @@ -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), + ) + ], + ), + ); + } +}