nanoid_generator 1.0.2
nanoid_generator: ^1.0.2 copied to clipboard
A secure, URL-friendly, unique string ID generator for Dart. Generate cryptographically secure, collision-resistant IDs with customizable size and alphabet using Random.secure().
import 'package:flutter/material.dart';
import 'package:nanoid_generator/nanoid_generator.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'NanoID Generator',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
),
home: const MyHomePage(title: 'NanoID Generator'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String _nanoId = nanoid();
void _generateNewNanoId() {
setState(() {
_nanoId = nanoid();
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'Generated NanoID:',
style: TextStyle(fontSize: 18),
),
const SizedBox(height: 20),
SelectableText(
_nanoId,
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _generateNewNanoId,
tooltip: 'Generate New NanoID',
child: const Icon(Icons.refresh),
),
);
}
}