-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.dart
158 lines (143 loc) · 4.59 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import 'package:flutter/material.dart';
import 'package:ionicons/ionicons.dart';
import 'package:url_launcher/url_launcher_string.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Ionicons',
theme: ThemeData(primarySwatch: Colors.blue),
debugShowCheckedModeBanner: false,
home: MyHomePage(),
);
}
}
/// Example page
class MyHomePage extends StatelessWidget {
final _outlineItems = ValueNotifier<List<MapEntry<String, String>>>([]);
final _filledItems = ValueNotifier<List<MapEntry<String, String>>>([]);
final _sharpItems = ValueNotifier<List<MapEntry<String, String>>>([]);
MyHomePage({Key? key}) : super(key: key) {
_onTextChanged(''); // trigger the search
}
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
title: const Text('Flutter Ionicons'),
bottom: const TabBar(tabs: [
Tab(text: 'Outline'),
Tab(text: 'Filled'),
Tab(text: 'Sharp'),
]),
actions: [
IconButton(
onPressed: _onPressedGitHub,
icon: const Icon(Ionicons.logo_github),
),
TextButton(
onPressed: _onPressedPub,
child: const Text(
'v0.2.1',
style: TextStyle(color: Colors.white),
),
),
],
),
body: Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 16),
child: TextField(
autofocus: true,
decoration: const InputDecoration(
hintText: 'Search icons',
prefixIcon: Padding(
padding: EdgeInsets.only(left: 32, right: 16),
child: Icon(Ionicons.search_outline),
),
),
onChanged: _onTextChanged,
),
),
Expanded(
child: TabBarView(
children: [
ValueListenableBuilder<dynamic>(
valueListenable: _outlineItems,
builder: (context, value, child) => _ItemList(items: value),
),
ValueListenableBuilder<dynamic>(
valueListenable: _filledItems,
builder: (context, value, child) => _ItemList(items: value),
),
ValueListenableBuilder<dynamic>(
valueListenable: _sharpItems,
builder: (context, value, child) => _ItemList(items: value),
),
],
),
),
],
),
),
);
}
/// Handle on search icons
void _onTextChanged(String value) {
final items = value.isEmpty
? ioniconsMapping.entries.toList()
: ioniconsMapping.entries
.where((e) => e.key.contains(value.toLowerCase()))
.toList();
_outlineItems.value =
items.where((e) => e.key.endsWith('-outline')).toList();
_filledItems.value = items
.where((e) => !(e.key.endsWith('-outline') || e.key.endsWith('-sharp')))
.toList();
_sharpItems.value = items.where((e) => e.key.endsWith('-sharp')).toList();
}
/// Handle on pressed GitHub button
void _onPressedGitHub() {
launchUrlString('https://github.com/ez-connect/flutter-ionicons');
}
/// Handle on pressed Pub button
void _onPressedPub() {
launchUrlString('https://pub.dev/packages/ionicons');
}
}
/// Render the list of icons
class _ItemList extends StatelessWidget {
final List<MapEntry<String, String>> items;
final _controller = ScrollController();
_ItemList({Key? key, required this.items}) : super(key: key);
@override
Widget build(BuildContext context) {
return GridView.extent(
controller: _controller,
maxCrossAxisExtent: 86,
childAspectRatio: 0.7,
children: List.generate(items.length, (index) {
final item = items[index];
return Column(
children: [
Icon(IoniconsData(int.parse(item.value)), size: 64),
const SizedBox(height: 8),
Text(
item.key,
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 12),
),
],
);
}),
);
}
}