The most common conditional statement is used flutter if not boolean value. This is very commonly used in different logical functions. In this article, we will discuss logical operators and flutter if not boolean value. bool is the type of Dart that represents a boolean value that can be true or false.
Flutter If Not boolean Value
The logical operator is the same in all languages. In dart, there is no difference. The logical operator also uses to combine or invert the boolean expressions.
Operator | Meaning |
&& | Logical AND |
|| | Logical OR |
!expr | invert boolean |
Example 1:
bool isDownloading = true;
bool isConnection = false;
assert(!isDownloading ); // true
assert(isConnection || isDownloading ); // true because at least one is true
assert(isDownloading && !isConnection); // true because both are true
Example 2:
Let’s consider, we will download a new mp3 from the URL. The important books is isDownloadReady. When it was true, then app start downloading, if not then it will not download the mp3. There have a gallery so I use a bool ifStorageFull, so if it is true then will appear a message that the storage is full, delete some mp3. Let’s consider that the gallery exists 50 mp3.
bool ifStorageFull;
int mp3;
@override
Widget build(BuildContext context) {
if (mp3> 100) {
ifStorageFull= true;
} else {isStorageFull = false;}
return Container(
child: ifStorageFull? Text("Delete some images") : Text("You can add more pictures")
);
}
So the schema is:
if (fullfilled condition) {
yourBool = true;
} else {yourBool} = false;
Example 3:
// first assign
bool isFileExist = true;
bool isInternetConnection = true;
// we can combine boolean with &&, ||, and other symbols
// if isFileExist is true AND isInternetConnection is true
bool isDownloadAnotherFile = isFileExist && isInternetConnection;
if (isDownloadAnotherFile ) {
print("Downloading next file!");
} else {
print("Downloading current File!");
}
At last of Flutter If Not boolean Value
- Declare the bool with the name isAnyThing or isSomething. example: isDownloading, isFileExist.
- Variable true or false check.
- Execute the code after resulting in the true or false.
Read More: