obra_icons 1.0.0
obra_icons: ^1.0.0 copied to clipboard
Obra Icons as a Flutter icon font — 1,000+ consistent UI icons usable with the native Icon() widget. MIT licensed.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:obra_icons/obra_icons.dart';
void main() => runApp(const GalleryApp());
class GalleryApp extends StatelessWidget {
const GalleryApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Obra Icons',
theme: ThemeData(useMaterial3: true, colorSchemeSeed: Colors.indigo),
home: const GalleryPage(),
);
}
}
class GalleryPage extends StatefulWidget {
const GalleryPage({super.key});
@override
State<GalleryPage> createState() => _GalleryPageState();
}
class _GalleryPageState extends State<GalleryPage> {
// Three upstream icon names are Dart reserved words; the generator
// (tool/generate.mjs DART_RESERVED) prefixes them with `icon_`. Keep this
// in sync if future regenerations rename additional reserved-word icons.
static const Map<String, String> _reservedRemap = {
'export': 'icon_export',
'function': 'icon_function',
'switch': 'icon_switch',
};
String _query = '';
@override
Widget build(BuildContext context) {
final entries = ObraIcons.byName.entries
.where((e) => e.key.contains(_query.trim().toLowerCase()))
.toList();
return Scaffold(
appBar: AppBar(
title: Text('Obra Icons (${ObraIcons.all.length})'),
bottom: PreferredSize(
preferredSize: const Size.fromHeight(56),
child: Padding(
padding: const EdgeInsets.fromLTRB(16, 0, 16, 12),
child: TextField(
decoration: const InputDecoration(
prefixIcon: Icon(Icons.search),
hintText: 'Search icons…',
border: OutlineInputBorder(),
isDense: true,
),
onChanged: (v) => setState(() => _query = v),
),
),
),
),
body: GridView.builder(
padding: const EdgeInsets.all(12),
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 110,
mainAxisSpacing: 8,
crossAxisSpacing: 8,
childAspectRatio: 0.85,
),
itemCount: entries.length,
itemBuilder: (context, i) {
final entry = entries[i];
return InkWell(
onTap: () {
final name = _reservedRemap[entry.key] ?? entry.key.replaceAll('-', '_');
Clipboard.setData(ClipboardData(text: 'ObraIcons.$name'));
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Copied ObraIcons.$name'),
duration: const Duration(seconds: 1)),
);
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(entry.value, size: 28),
const SizedBox(height: 6),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: Text(entry.key,
style: const TextStyle(fontSize: 10),
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis),
),
],
),
);
},
),
);
}
}