Offstage(
offstage:false,
child: Container(
width: 200,
height: 200,
color: Colors.red,
),
),
Visibility(
visible:_offstage,
replacement:Text('data'),
maintainState:true,
child: Container(
width: 200,
height: 200,
color: Colors.yellow,
),
),
四种方式控制显隐
import 'package:flutter/material.dart';
class Test extends StatelessWidget {
bool isShow=false;
@override
Widget build(BuildContext context) {
return Container(
child: Row(
children: <Widget>[
Visibility(child: null,visible:false,),
Offstage(offstage:false,child:null),
Opacity(opacity: 1,child:null),
isShow?Text("显示"):SizedBox.shrink()
],
),
);
}
}
网友评论