优化 .sepWidget扩展 去除隐藏组件

master
张萌 3 years ago
parent e7394e647f
commit a56a407233

@ -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<ExampleListExt> {
@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),
),
),
]);
}
}

@ -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_num_ext.dart';
import 'package:example/extension/example_string_ext.dart'; import 'package:example/extension/example_string_ext.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
class MainExtention extends StatefulWidget { class MainExtention extends StatefulWidget {
MainExtention({Key key}) : super(key: key); MainExtention({Key key}) : super(key: key);
@ -44,6 +45,11 @@ class _MainExtentionState extends State<MainExtention> {
child: Text('String Ext'), child: Text('String Ext'),
icon: Icon(Icons.text_fields), icon: Icon(Icons.text_fields),
), ),
_innerButton(
onPressed: () => Get.to(ExampleListExt()),
child: Text('list Ext'),
icon: Icon(Icons.text_fields),
),
], ],
); );
} }

@ -1,9 +1,21 @@
import 'package:flutter/material.dart';
import 'package:ansu_ui/extension/num_extension.dart'; import 'package:ansu_ui/extension/num_extension.dart';
import 'package:flutter/material.dart';
extension SeparateExt on List<Widget> { extension SeparateExt on List<Widget> {
List<Widget> sepWidget({Widget? separate}) { List<Widget> sepWidget({
Widget? separate,
}) {
if (this.isEmpty) return []; 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) { return List.generate(this.length * 2 - 1, (index) {
if (index.isEven) if (index.isEven)
return this[index ~/ 2]; return this[index ~/ 2];

Loading…
Cancel
Save