diff --git a/example/lib/extension/example_list_ext.dart b/example/lib/extension/example_list_ext.dart new file mode 100644 index 0000000..3ba2945 --- /dev/null +++ b/example/lib/extension/example_list_ext.dart @@ -0,0 +1,61 @@ +import 'package:ansu_ui/extension/list_extension.dart'; +import 'package:example/codeviewer/code_segments.dart'; +import 'package:example/component/example_scaffold.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:velocity_x/velocity_x.dart'; + +class ExampleListExt extends StatefulWidget { + const ExampleListExt({Key key}) : super(key: key); + + @override + _ExampleListExtState createState() => _ExampleListExtState(); +} + +class _ExampleListExtState extends State { + @override + Widget build(BuildContext context) { + return ExampleScaffold( + title: 'String Ext', + text: (context) => CodeSegments.stringExt(context), + children: [ + Container( + color: Colors.blue, + child: Column( + children: [ + Container( + width: double.infinity, + height: 50.w, + color: Colors.red, + child: Text('1'), + ), + Visibility( + visible: true, + child: Container( + width: double.infinity, + height: 50.w, + color: Colors.red, + child: Text('2'), + ), + ), + Offstage( + offstage: true, + child: Container( + width: double.infinity, + height: 50.w, + color: Colors.red, + child: Text('2'), + ), + ), + Container( + width: double.infinity, + height: 50.w, + color: Colors.red, + child: Text('3'), + ), + ].sepWidget(separate: 10.w.heightBox), + ), + ), + ]); + } +} diff --git a/example/lib/main_extention.dart b/example/lib/main_extention.dart index 7fc320e..b2bdc0c 100644 --- a/example/lib/main_extention.dart +++ b/example/lib/main_extention.dart @@ -1,8 +1,9 @@ +import 'package:example/extension/example_list_ext.dart'; import 'package:example/extension/example_num_ext.dart'; import 'package:example/extension/example_string_ext.dart'; import 'package:flutter/material.dart'; -import 'package:get/get.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:get/get.dart'; class MainExtention extends StatefulWidget { MainExtention({Key key}) : super(key: key); @@ -44,6 +45,11 @@ class _MainExtentionState extends State { child: Text('String Ext'), icon: Icon(Icons.text_fields), ), + _innerButton( + onPressed: () => Get.to(ExampleListExt()), + child: Text('list Ext'), + icon: Icon(Icons.text_fields), + ), ], ); } diff --git a/lib/extension/list_extension.dart b/lib/extension/list_extension.dart index c3e8b86..172bb6a 100644 --- a/lib/extension/list_extension.dart +++ b/lib/extension/list_extension.dart @@ -1,9 +1,21 @@ -import 'package:flutter/material.dart'; import 'package:ansu_ui/extension/num_extension.dart'; +import 'package:flutter/material.dart'; extension SeparateExt on List { - List sepWidget({Widget? separate}) { + List sepWidget({ + Widget? separate, + }) { if (this.isEmpty) return []; + this.removeWhere((element) { + if (element.runtimeType == Offstage) { + return (element as Offstage).offstage; + } + + if (element.runtimeType == Visibility) { + return (element as Visibility).visible; + } + return false; + }); return List.generate(this.length * 2 - 1, (index) { if (index.isEven) return this[index ~/ 2];