flutter
flutter 위젯에서 조건문 사용하기
햎피
2022. 6. 19. 18:18
반응형
플러터에서는 if/else, switch 문을 이용해서 위젯에 조건문을 줄 수 있다.
그리고 간편하게 ternary operator(삼항 조건 연산자)를 사용할 수도 있다.
class SaveBtn extends StatelessWidget {
SaveBtn({Key? key}) : super(key: key);
late QuillModel quillmodel;
late Pcontents pcontents;
@override
Widget build(BuildContext context) {
quillmodel = Provider.of<QuillModel>(context);
pcontents = Provider.of<Pcontents>(context);
return Container(
margin: EdgeInsets.fromLTRB(0, 0, 30, 0),
child: OutlinedButton(
child: pcontents.contents==true? Text("저장",
style: TextStyle(color: Colors.black, fontSize: 15.0)): Text("수정"),
onPressed: () async {
PromiseSave().saveFile(quillmodel.quillController.document.toDelta().toString());
Navigator.pop(context);
}));
}
}
반응형