forked from lxm_flutter/FlutterUnit
优化折叠面板代码
This commit is contained in:
@@ -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<WidgetNodePanel>
|
||||
with SingleTickerProviderStateMixin {
|
||||
bool _showCode = false;
|
||||
|
||||
class _WidgetNodePanelState extends State<WidgetNodePanel> {
|
||||
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<WidgetNodePanel>
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Row(
|
||||
children: <Widget>[
|
||||
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<WidgetNodePanel>
|
||||
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: <Widget>[
|
||||
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,
|
||||
);
|
||||
}
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user