From 174bc72f91cef3731501fcd848782af63b904f3a Mon Sep 17 00:00:00 2001 From: toly <1981462002@qq.com> Date: Sat, 18 Apr 2020 07:14:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8A=98=E5=8F=A0=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/components/project/widget_node_panel.dart | 183 ++++++++++-------- 1 file changed, 99 insertions(+), 84 deletions(-) diff --git a/lib/components/project/widget_node_panel.dart b/lib/components/project/widget_node_panel.dart index 6a6d44f..36662d9 100644 --- a/lib/components/project/widget_node_panel.dart +++ b/lib/components/project/widget_node_panel.dart @@ -13,7 +13,7 @@ import '../permanent/code/highlighter_style.dart'; /// create by 张风捷特烈 on 2020-04-13 /// contact me by email 1981462002@qq.com -/// 说明: +/// 说明: 一个Widget的知识点对应的界面 class WidgetNodePanel extends StatefulWidget { final String text; @@ -23,20 +23,25 @@ class WidgetNodePanel extends StatefulWidget { final HighlighterStyle codeStyle; final String codeFamily; - WidgetNodePanel({this.text, this.subText, this.code, this.show,this.codeStyle,this.codeFamily}); + WidgetNodePanel( + {this.text, + this.subText, + this.code, + this.show, + this.codeStyle, + this.codeFamily}); @override _WidgetNodePanelState createState() => _WidgetNodePanelState(); } -class _WidgetNodePanelState extends State - with SingleTickerProviderStateMixin { - bool _showCode = false; - +class _WidgetNodePanelState extends State { var _crossFadeState = CrossFadeState.showFirst; bool get isFirst => _crossFadeState == CrossFadeState.showFirst; + Color get themeColor => Theme.of(context).primaryColor; + @override Widget build(BuildContext context) { return Container( @@ -44,60 +49,7 @@ class _WidgetNodePanelState extends State child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ - Row( - children: [ - Padding( - padding: const EdgeInsets.symmetric(horizontal: 8), - child: Circle( - color: Theme.of(context).primaryColor, - radius: 5, - ), - ), - Expanded( - child: Text( - '${widget.text}', - style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16), - ), - ), - FeedbackWidget( - mode: FeedMode.fade, - a: 0.4, - onPressed: () async { -// await Clipboard.setData(ClipboardData(text: widget.code)); -// Toast.toast(context, '复制成功!'); - Share.share(widget.code); - }, - child: Padding( - padding: const EdgeInsets.only( - right: 10, - ), - child: Icon( - TolyIcon.icon_share, - size: 20, - color: Theme.of(context).primaryColor, - ), - ), - ), - Padding( - padding: const EdgeInsets.only(right: 10.0), - child: ToggleRotate( - durationMs: 300, - child: Icon( - TolyIcon.icon_code, - color: Theme.of(context).primaryColor, - ), - onTap: () { - setState(() { - _crossFadeState = _showCode - ? CrossFadeState.showFirst - : CrossFadeState.showSecond; - _showCode = !_showCode; - }); - }, - ), - ) - ], - ), + buildNodeTitle(), SizedBox( height: 20, ), @@ -106,34 +58,97 @@ class _WidgetNodePanelState extends State padding: const EdgeInsets.only(top: 10, bottom: 20), child: widget.show, ), - Container( - width: double.infinity, - child: Panel( - child: Text( - '${widget.subText}', - style: TextStyle(fontSize: 14), - )), - ), + _buildNodeInfo(), Divider(), ], ), ); } + Widget buildNodeTitle() => Row( + children: [ + Padding( + padding: const EdgeInsets.symmetric(horizontal: 8), + child: Circle( + color: themeColor, + radius: 5, + ), + ), + Expanded( + child: Text( + '${widget.text}', + style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16), + ), + ), + _buildShareButton(), + _buildCodeButton() + ], + ); + + Widget _buildNodeInfo() => Container( + width: double.infinity, + child: Panel( + child: Text( + '${widget.subText}', + style: TextStyle(fontSize: 14), + )), + ); + + Widget _buildCodeButton() => Padding( + padding: const EdgeInsets.only(right: 10.0), + child: ToggleRotate( + durationMs: 300, + child: Icon( + TolyIcon.icon_code, + color: themeColor, + ), + onTap: _toggleCodePanel, + ), + ); + + Widget _buildShareButton() => FeedbackWidget( + mode: FeedMode.fade, + a: 0.4, + onPressed: _doShare, + child: Padding( + padding: const EdgeInsets.only( + right: 10, + ), + child: Icon( + TolyIcon.icon_share, + size: 20, + color: themeColor, + ), + ), + ); + Widget _buildCode(BuildContext context) => AnimatedCrossFade( - firstCurve: Curves.easeInCirc, - secondCurve: Curves.easeInToLinear, - firstChild: Container(), - secondChild: Container( - width: MediaQuery.of(context).size.width, - child: CodeWidget( - fontFamily: widget.codeFamily, - code: widget.code, - style: widget.codeStyle??HighlighterStyle.fromColors( - HighlighterStyle.lightColor), - ), - ), - duration: Duration(milliseconds: 500), - crossFadeState: _crossFadeState, - ); -} \ No newline at end of file + firstCurve: Curves.easeInCirc, + secondCurve: Curves.easeInToLinear, + firstChild: Container(), + secondChild: Container( + width: MediaQuery.of(context).size.width, + child: CodeWidget( + fontFamily: widget.codeFamily, + code: widget.code, + style: widget.codeStyle ?? + HighlighterStyle.fromColors(HighlighterStyle.lightColor), + ), + ), + duration: Duration(milliseconds: 500), + crossFadeState: _crossFadeState, + ); + + //执行分享 + _doShare() { + Share.share(widget.code); + } + + // 折叠代码面板 + _toggleCodePanel() { + setState(() { + _crossFadeState = + !isFirst ? CrossFadeState.showFirst : CrossFadeState.showSecond; + }); + } +}