-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_crag.dart
95 lines (90 loc) · 2.7 KB
/
add_crag.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
import 'package:flutter/material.dart';
import 'model/crag.dart';
import 'database.dart';
class AddCragScreen extends StatelessWidget {
final Crag? passedCrag;
AddCragScreen({this.passedCrag}) {
if (passedCrag != null) {
nameController.text = passedCrag!.name!;
countryController.text = passedCrag!.country!;
}
}
final TextEditingController nameController = new TextEditingController();
final TextEditingController countryController = new TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Add Crag"),
),
body: Container(
padding: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
SizedBox(
width: 100,
child: Text(
'Crag Name',
style: Theme.of(context).textTheme.bodyLarge,
),
),
Flexible(
child: TextField(
controller: nameController,
),
),
],
),
Row(
children: [
SizedBox(
width: 100,
child: Text(
'Country',
style: Theme.of(context).textTheme.bodyLarge,
),
),
Flexible(
child: TextField(controller: countryController),
),
],
),
// buttons below
SizedBox(
height: 50,
),
Row(
children: [
ElevatedButton(
onPressed: () {
Navigator.pop(context);
},
child: Text('Cancel'),
),
SizedBox(
width: 10,
),
ElevatedButton(
onPressed: () {
if (passedCrag != null) {
passedCrag!.name = nameController.text;
passedCrag!.country = countryController.text;
DatabaseHelper.updateCrag(passedCrag!);
} else {
Crag crag = new Crag(name: nameController.text, country: countryController.text);
DatabaseHelper.addCrag(crag);
}
Navigator.pop(context);
},
child: Text(passedCrag != null ? 'Update' : 'Add'),
),
],
),
],
),
),
);
}
}