-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_symbol_page.dart
141 lines (130 loc) · 4.07 KB
/
list_symbol_page.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:gap/gap.dart';
import 'package:mapbox_gl/mapbox_gl.dart';
import 'class_definition.dart';
import 'util_common.dart';
class ListSymbolPage extends StatefulWidget {
const ListSymbolPage({Key? key}) : super(key: key);
@override
ListSymbolPageState createState() => ListSymbolPageState();
}
class ListSymbolPageState extends State<ListSymbolPage> {
List<SymbolInfoWithLatLng> _infoList = [];
String _keyword = '';
List<SymbolInfoWithLatLng> _filtered = [];
@override
Widget build(BuildContext context) {
final args = ModalRoute.of(context)!.settings.arguments as FullSymbolList;
_infoList = args.infoList;
_viewList();
return Scaffold(
appBar: PreferredSize(
preferredSize: const Size.fromHeight(60.0),
child: AppBar(
title: TextField(
decoration: const InputDecoration(
prefixIcon: Icon(Icons.search),
hintText: 'タイトル・地域検索',
fillColor: Colors.white,
filled: true,
border: InputBorder.none,
),
onChanged: (value) => {_keywordChangeAndViewList(value)}),
),
),
body: _makeDisplayForm(),
);
}
// 表示フォームウィジェット
Widget _makeDisplayForm() {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Align(
alignment: Alignment.topLeft,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Gap(12),
Flexible(
child: ListView.builder(
itemCount: _filtered.length,
itemBuilder: (BuildContext context, int index) {
return _symbolInfoItem(_filtered[index]);
},
),
),
],
),
),
);
}
// 項目表示ウィジェット
Widget _symbolInfoItem(SymbolInfoWithLatLng symbolInfoWithLatLng) {
final String title = formatLabel(symbolInfoWithLatLng.symbolInfo.title, 13);
final String prefMuniText =
'${symbolInfoWithLatLng.symbolInfo.prefMuni.prefecture}${symbolInfoWithLatLng.symbolInfo.prefMuni.municipalities}';
final String dateTimeText =
symbolInfoWithLatLng.symbolInfo.dateTime.toString().substring(0, 19);
return Card(
child: Container(
decoration: BoxDecoration(
border: Border.all(width: 1.0, color: Colors.blue),
),
child: ListTile(
leading: (const Icon(
Icons.location_on,
size: 30.0,
)),
title: Text(title),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(prefMuniText),
Text(dateTimeText),
],
),
onTap: () {
Navigator.pop(
context,
LatLng(symbolInfoWithLatLng.latLng.latitude,
symbolInfoWithLatLng.latLng.longitude));
},
),
),
);
}
// キーワードを変更して一覧を表示
void _keywordChangeAndViewList(keyword) {
setState(() {
_keyword = keyword;
});
_viewList;
}
// 一覧を表示
void _viewList() {
setState(() {
_filtered = _filterList();
});
}
// 一覧の対象をフィルタ
List<SymbolInfoWithLatLng> _filterList() {
if (_keyword == '') {
return _infoList;
}
final List<SymbolInfoWithLatLng> filtered = [];
for (int i = 0; i < _infoList.length; i++) {
if (_infoList[i]
.symbolInfo
.title
.toLowerCase()
.contains(_keyword.toLowerCase()) ||
_infoList[i].symbolInfo.prefMuni.prefecture.contains(_keyword) ||
_infoList[i].symbolInfo.prefMuni.municipalities.contains(_keyword) ||
_infoList[i].symbolInfo.prefMuni.getPrefMuni().contains(_keyword)) {
filtered.add(_infoList[i]);
}
}
return filtered;
}
}