Skip to content

Commit

Permalink
Allow copying icon name in icon overview page
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbendebiene committed Dec 1, 2022
1 parent 9dcdd9b commit 2dc58b5
Showing 1 changed file with 57 additions and 23 deletions.
80 changes: 57 additions & 23 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:reflectable/reflectable.dart';
import 'main.reflectable.dart';
import 'package:temaki_flutter/temaki_flutter.dart';
Expand All @@ -19,20 +20,20 @@ class MyApp extends StatelessWidget {
return MaterialApp(
title: 'Flutter Temaki Icon Example',
theme: ThemeData.dark(),
home: const MyHomePage(),
home: const IconOverviewPage(),
);
}
}

class MyHomePage extends StatefulWidget {
class IconOverviewPage extends StatefulWidget {

const MyHomePage({super.key});
const IconOverviewPage({super.key});

@override
State<MyHomePage> createState() => _MyHomePageState();
State<IconOverviewPage> createState() => _IconOverviewPageState();
}

class _MyHomePageState extends State<MyHomePage> {
class _IconOverviewPageState extends State<IconOverviewPage> {
final _classMirror = reflector.reflectType(TemakiIcons) as ClassMirror;
late final _icons = _classMirror.staticMembers.keys.toList();

Expand All @@ -51,23 +52,9 @@ class _MyHomePageState extends State<MyHomePage> {
),
itemCount: _icons.length,
itemBuilder: (BuildContext context, int index) {
return Card(
margin: const EdgeInsets.all(10),
elevation: 4,
child: Padding(
padding: const EdgeInsets.all(15),
child: Column(
children: [
Expanded(
child: Icon(
_classMirror.invokeGetter(_icons[index]) as IconData,
size: 45,
),
),
Text(_icons[index]),
],
),
),
return IconCard(
name: _icons[index],
icon: _classMirror.invokeGetter(_icons[index]) as IconData,
);
},
),
Expand All @@ -76,9 +63,56 @@ class _MyHomePageState extends State<MyHomePage> {
}
}

class IconCard extends StatelessWidget {
final String name;
final IconData icon;

const IconCard({
required this.name,
required this.icon,
super.key,
});

@override
Widget build(BuildContext context) {
return Card(
margin: const EdgeInsets.all(10),
elevation: 4,
child: InkWell(
onTap: () async {
final scaffoldRef = ScaffoldMessenger.of(context);
await Clipboard.setData(ClipboardData(text: name));
if (scaffoldRef.mounted) {
scaffoldRef.hideCurrentSnackBar();
scaffoldRef.showSnackBar(SnackBar(
content: Text('Copied "$name" to clipboard'),
duration: const Duration(seconds: 2),
behavior: SnackBarBehavior.floating,
width: 300,
));
}
},
child: Padding(
padding: const EdgeInsets.all(15),
child: Column(
children: [
Expanded(
child: Icon(icon,
size: 45,
),
),
Text(name),
],
),
),
),
);
}
}


class Reflector extends Reflectable {
// define required capabillities
// define required capabilities
const Reflector() : super(
staticInvokeCapability,
declarationsCapability,
Expand Down

0 comments on commit 2dc58b5

Please sign in to comment.