showDialog(context: context,builder: (context) {String label = 'test';//StatefulBuilderreturn StatefulBuilder(//在这里为了区分,在构建builder的时候将setState方法命名为了setDialogState。builder: (context, setDialogState) {print('label = $label');return GestureDetector(child: Text(label),onTap: () {label = 'test8';print('onTap:label = $label');// 注意不是调用老页面的setState,而是要调用builder中的setDialogState。setDialogState(() {}); },);},);});
bottomsheet
bool btnState=false;
showModalBottomSheet(context:context, builder:(BuildContext context){return StatefulBuilder(//在这里为了区分,在构建builder的时候将setState方法命名为了setBottomSheetState。builder:(context1, setBottomSheetState) {return Container(child:OutlineButton(onPressed: (){// 注意不是调用老页面的setState,而是要调用builder中的setBottomSheetStatesetBottomSheetState(() {btnState=!btnState;});},child:Stack(children: <Widget>[Opacity(opacity: btnState ? 0.0 : 1.0,child: Text("aa"),),Opacity(opacity: btnState ? 1.0 : 0.0,child: Text("bb"),),],),),),})}
)