/
main.dart
141 lines (130 loc) · 4.07 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
import 'package:flutter/material.dart';
import 'package:crypto_font_icons_example/icons.dart';
void main() {
runApp(new CryptoFontGalleryApp());
}
class CryptoFontGalleryApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'CryptoFont Flutter Gallery',
theme: ThemeData.light().copyWith(
iconTheme: IconThemeData(size: 36.0, color: Colors.black87),
textTheme: TextTheme(
bodyText1: TextStyle(fontSize: 16.0, color: Colors.black87),
),
),
home: CryptoFontGalleryHome(),
);
}
}
class CryptoFontGalleryHome extends StatefulWidget {
@override
State<StatefulWidget> createState() => CryptoFontGalleryHomeState();
}
class CryptoFontGalleryHomeState extends State<CryptoFontGalleryHome> {
var _searchTerm = "";
var _isSearching = false;
@override
Widget build(BuildContext context) {
final filteredIcons = icons
.where((icon) => _searchTerm.isEmpty || icon.title.toLowerCase().contains(_searchTerm.toLowerCase()))
.toList();
final orientation = MediaQuery.of(context).orientation;
return new Scaffold(
appBar: _isSearching ? _searchBar(context) : _titleBar(),
body: new GridView.builder(
itemCount: filteredIcons.length,
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: orientation == Orientation.portrait ? 2 : 3,
),
itemBuilder: (context, index) {
final icon = filteredIcons[index];
return new InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute<Null>(
builder: (BuildContext context) {
return GestureDetector(
onTap: () {
Navigator.of(context).pop();
},
child: Container(
color: Colors.white,
child: SizedBox.expand(
child: Hero(
tag: icon,
child: Icon(
icon.iconData,
size: 100.0,
),
),
),
),
);
},
),
);
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Hero(tag: icon, child: Icon(icon.iconData)),
Container(
padding: EdgeInsets.only(top: 16.0),
child: Text(icon.title),
)
],
),
);
}),
);
}
AppBar _titleBar() {
return AppBar(
title: Text("CryptoFont Flutter Gallery"),
actions: [
IconButton(
icon: Icon(Icons.search),
onPressed: () {
ModalRoute.of(context)?.addLocalHistoryEntry(
LocalHistoryEntry(
onRemove: () {
setState(() {
_searchTerm = "";
_isSearching = false;
});
},
),
);
setState(() {
_isSearching = true;
});
})
],
);
}
AppBar _searchBar(BuildContext context) {
return AppBar(
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
setState(
() {
Navigator.pop(context);
_isSearching = false;
_searchTerm = "";
},
);
},
),
title: new TextField(
onChanged: (text) => setState(() => _searchTerm = text),
autofocus: true,
style: new TextStyle(fontSize: 18.0),
decoration: new InputDecoration(border: InputBorder.none),
),
);
}
}