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 String")
),
body: bodyContent()
),
),
);
}
bodyContent(){
const chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz'
'1234567890';
String getRandomString([int length = 8]) => String.fromCharCodes(
Iterable.generate(
length, (_) => chars.codeUnitAt(
Random().nextInt(chars.length))
)
);
return Center(
child: Container(
color: Colors.black12,
alignment: Alignment.center,
height: 200,
margin: const EdgeInsets.all(16),
child: Text(
getRandomString(12),
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 30
)
),
),
);
}
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 bool
- flutter – Random bool custom probability
- flutter – How to generate random uuid
- flutter – How to use Google Fonts