xxxxxxxxxx
import 'package:flutter/material.dart';
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
bool condition = true; // Modify the condition as needed
return Scaffold(
body: Center(
child: condition
? Text('Condition is true!')
: Text('Condition is false!'),
),
);
}
}
xxxxxxxxxx
it will work inside an widget.
Column(
children: [
if(a > 10) [
Text("A is greater than 10"),
]else [
Text("A is less than or Equal to 10")
]
])
Normally:
int time = 6;
if(time > 12) {
time = time - 12;
print('$time PM');
}else {
print('$time AM');
};
flutter if statement inside widget
xxxxxxxxxx
Container(
child: loading? //check if loading is true or false
CircularProgressIndicator(): //show progress on loading = true
Text("Loaded"), //show this text on loading = false
)