Last active
March 15, 2021 12:25
-
-
Save mukhtharcm/0f7f56b1ac8d25939bc53e2397edcac6 to your computer and use it in GitHub Desktop.
Example for using ternary operator in Flutter.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: MyWidget(), | |
), | |
), | |
); | |
} | |
} | |
class MyWidget extends StatefulWidget { | |
@override | |
_MyWidgetState createState() => _MyWidgetState(); | |
} | |
class _MyWidgetState extends State<MyWidget> { | |
bool isLoading = true; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
isLoading ? CircularProgressIndicator() : Text("Loading Completed"), | |
SizedBox(height: 100), | |
Text("Click Button to Toggle Loading"), | |
SizedBox(height: 50), | |
ElevatedButton( | |
onPressed: () { | |
setState(() { | |
isLoading = !isLoading; | |
}); | |
}, | |
child: Text("Toggle Loading"), | |
) | |
], | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
setState(() { | |
isLoading = !isLoading; | |
}); | |
}, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment