大佬教程收集整理的这篇文章主要介绍了颤抖 – 我想通过onLongPress选择卡?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
import 'package:Flutter/material.dart'; void main() => runApp(new MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return new MaterialApp( title: 'NonStopIO',theme: new ThemeData( priMarySwatch: Colors.red,),home: new MyHomePage(),); } } class MyHomePage extends StatefulWidget { @override _MyHomePageState createState() => new _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { bool longPressFlag = false; List<int> indexList = new List(); void longPress() { setState(() { if (indexList.isEmpty) { longPressFlag = false; } else { longPressFlag = true; } }); } @override Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar( title: new Text('SELEcted ${indexList.length} ' + indexList.toString()),body: new ListView.builder( itemCount: 3,itemBuilder: (context,indeX) { return new CustomWidget( index: index,longPressEnabled: longPressFlag,callBACk: () { if (indexList.contains(indeX)) { indexList.remove(indeX); } else { indexList.add(indeX); } longPress(); },); },floaTingActionButton: new FloaTingActionButton( onPressed: () {},tooltip: 'Increment',child: new Icon(Icons.add),// This Trailing comma makes auto-formatTing nicer for build methods. ); } } class CustomWidget extends StatefulWidget { final int index; final bool longPressEnabled; final VoidCallBACk callBACk; const customWidget({Key key,this.index,this.longPressEnabled,this.callBACk}) : super(key: key); @override _CustomWidgetState createState() => new _CustomWidgetState(); } class _CustomWidgetState extends State<CustomWidget> { bool SELEcted = false; @override Widget build(BuildContext context) { return new GestureDetector( onLongPress: () { setState(() { SELEcted = !SELEcted; }); widget.callBACk(); },onTap: () { if (widget.longPressEnabled) { setState(() { SELEcted = !SELEcted; }); widget.callBACk(); } },child: new Container( margin: new EdgeInsets.all(5.0),child: new ListTile( title: new Text("title ${widget.index}"),subtitle: new Text("Description ${widget.index}"),decoration: SELEcted ? new BoxDecoration(color: Colors.black38,border: new Border.all(color: Colors.black)) : new BoxDecoration(),); } }
以上是大佬教程为你收集整理的颤抖 – 我想通过onLongPress选择卡?全部内容,希望文章能够帮你解决颤抖 – 我想通过onLongPress选择卡?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。