-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_symbol_info_page.dart
117 lines (109 loc) · 3.54 KB
/
edit_symbol_info_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
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:gap/gap.dart';
import 'class_definition.dart';
class EditSymbolInfoPage extends StatefulWidget {
const EditSymbolInfoPage({Key? key}) : super(key: key);
@override
EditSymbolInfoPageState createState() => EditSymbolInfoPageState();
}
class EditSymbolInfoPageState extends State<EditSymbolInfoPage> {
String _title = '';
PrefMuni? _prefMuni;
String _describe = '';
DateTime _dateTime = DateTime.now();
bool _isError = false;
@override
Widget build(BuildContext context) {
final args = ModalRoute.of(context)!.settings.arguments as SymbolInfo;
_title = args.title;
_prefMuni = args.prefMuni;
_describe = args.describe;
_dateTime = args.dateTime;
final titleBar = (_title == '' ? 'ピン情報登録' : 'ピン情報変更');
return Scaffold(
appBar: AppBar(
title: Text(titleBar),
),
body: _makeInputForm(),
);
}
// 入力フォームウィジェット
Widget _makeInputForm() {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Wrap(
children: <Widget>[
Align(
alignment: Alignment.topCenter,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Gap(16),
TextFormField(
initialValue: _title,
autofocus: true,
maxLength: 20,
maxLengthEnforcement: MaxLengthEnforcement.none,
decoration: const InputDecoration(
hintText: 'タイトルを入力してください',
labelText: 'タイトル *',
),
maxLines: 1,
onChanged: (String text) => _title = text,
),
Center(
child: Text(
(_isError ? 'タイトルを入力してください' : ' '),
style: const TextStyle(color: Colors.red),
),
),
const Gap(16),
TextFormField(
initialValue: _describe,
maxLength: 240,
maxLengthEnforcement: MaxLengthEnforcement.none,
decoration: const InputDecoration(
hintText: '説明文を入力してください',
labelText: '説明',
),
maxLines: null,
onChanged: (String text) => _describe = text,
),
const Gap(16),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
TextButton(
child: const Text('キャンセル'),
onPressed: () {
Navigator.pop(context, null);
},
),
TextButton(
child: const Text('保存'),
onPressed: () {
_saveSymbolInfo(context);
},
),
],
),
],
),
),
],
),
);
}
// 保存
void _saveSymbolInfo(BuildContext context) {
if (_title == '') {
setState(() {
_isError = true;
});
return;
}
Navigator.pop(
context, SymbolInfo(_title, _describe, _dateTime, _prefMuni!));
}
}