main.dart
import 'dart:math';
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
theme: ThemeData(primarySwatch: Colors.amber),
home: Scaffold(
appBar: AppBar(
title: const Text("Flutter - Random Boolean")
),
body: bodyContent()
),
),
);
}
bodyContent(){
return Column(children: [box(),box(),box(),box(),box()]);
}
box(){
bool randomBool = Random().nextBool();
return Container(
height: 85, width: double.infinity,
color: randomBool? Colors.green.shade200 : Colors.pink.shade200,
margin: const EdgeInsets.all(8),
child: Text(
randomBool.toString().toUpperCase(),
style: const TextStyle(fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
alignment: Alignment.center
);
}
More flutter tutorials
- flutter – ListTile border
- flutter – ListTile border bottom
- flutter – ListTile remove padding
- flutter – Space between ListTile leading and title
- flutter – ListTile shape
- flutter – ListTile separator
- flutter – How to use Table
- flutter – Random number in range
- flutter – Random material color
- flutter – Random material color with shade
- flutter – Get random element from a list
- flutter – How to generate random string
- flutter – How to use Google Fonts
- flutter – Google fonts text theme
- flutter – Function default value