Added Navigator pane to edit entries... Doesn't work if you edit parts though

This commit is contained in:
anthonycicc 2018-05-12 14:25:55 -04:00
parent ba829a16e8
commit 67f115b798
3 changed files with 153 additions and 128 deletions

134
lib/NoZeroDays.dart Normal file
View file

@ -0,0 +1,134 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:nomorezerodays/Entry.dart';
class NoZeroDays extends StatefulWidget {
NoZeroDays({Key key, this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
_NoZeroDaysState createState() => new _NoZeroDaysState();
}
class _NoZeroDaysState extends State<NoZeroDays> {
static List<Entry> _firstEntry = <Entry>[
Entry(new DateTime.now(), "Made this!")
];
List<Entry> _zerodayslist = new List<Entry>.from(_firstEntry);
Future<DateTime> _currentDatePicker() {
int currentYear = new DateTime.now().year;
return showDatePicker(
context: (context),
initialDate: new DateTime.now(),
firstDate: new DateTime(currentYear),
lastDate: new DateTime(currentYear + 1));
}
Widget _buildFAB() {
return new FloatingActionButton(
onPressed: () {
Future<DateTime> pickedDate = _currentDatePicker();
pickedDate.then((value) {
setState(() {
if (value != null) _zerodayslist.add(Entry(value, "nothing"));
});
}).catchError((err) {
Scaffold
.of(context)
.showSnackBar(new SnackBar(content: new Text(err.toString())));
});
},
tooltip: 'Make a new entry',
child: new Icon(Icons.add),
);
}
Widget _buildRow(Entry entry) {
return new ListTile(
title: new Text(entry.toString()),
onTap: () {
_editEntry(entry);
},
trailing: new Icon(Icons.edit),
);
}
void _editEntry(Entry entry) {
Navigator.of(context).push(
new MaterialPageRoute(
builder: (context) {
final t = new Form(
child: new Column(
children: <Widget>[
new IconButton(icon: new Icon(Icons.date_range), onPressed:
() {
Future<DateTime> newDate = showDatePicker(
context: (context),
initialDate: entry.date,
firstDate: new DateTime(DateTime.now().year),
lastDate: new DateTime(DateTime.now().year + 1)
);
newDate.then((newValue) {
setState(() {
_zerodayslist.remove(entry);
_zerodayslist.add(
new Entry(newValue, entry.whatYouDid));
});
});
}),
new TextFormField(
initialValue: entry.whatYouDid,
onFieldSubmitted: (newValue) {
setState((){
_zerodayslist.remove(entry);
_zerodayslist.add(new Entry(entry.date, newValue));
});
},
)
],
),
);
return new Scaffold(
appBar: new AppBar(title: new Text("Edit this entry")),
body: t,
);
})
);
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: new Scaffold(body: new ListView.builder(
itemBuilder: (context, entry) {
if (entry < _zerodayslist.length) {
return _buildRow(_zerodayslist[entry]);
} else
return new ListTile();
},
)),
floatingActionButton: _buildFAB(),
);
}
}

View file

@ -1,7 +1,6 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:nomorezerodays/Entry.dart';
import 'package:nomorezerodays/NoZeroDays.dart';
void main() => runApp(new MyApp());
@ -24,91 +23,4 @@ class MyApp extends StatelessWidget {
),
home: new Scaffold(body: new NoZeroDays(title: 'No Zero Days!')));
}
}
class NoZeroDays extends StatefulWidget {
NoZeroDays({Key key, this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
_NoZeroDaysState createState() => new _NoZeroDaysState();
}
class _NoZeroDaysState extends State<NoZeroDays> {
static List<Entry> _firstEntry = <Entry>[
Entry(new DateTime.now(), "Made this!")
];
List<Entry> _zerodayslist = new List<Entry>.from(_firstEntry);
Future<DateTime> _currentDatePicker() {
int currentYear = new DateTime.now().year;
return showDatePicker(
context: (context),
initialDate: new DateTime.now(),
firstDate: new DateTime(currentYear),
lastDate: new DateTime(currentYear + 1));
}
Widget _buildFAB() {
return new FloatingActionButton(
onPressed: () {
Future<DateTime> pickedDate = _currentDatePicker();
pickedDate.then((value) {
setState(() {
if (value != null) _zerodayslist.add(Entry(value, "nothing"));
});
}).catchError((err) {
Scaffold
.of(context)
.showSnackBar(new SnackBar(content: new Text(err.toString())));
});
},
tooltip: 'Make a new entry',
child: new Icon(Icons.add),
);
}
Widget _buildRow(Entry entry) {
return new ListTile(
title: new Text(entry.toString()),
onTap: () {
//edit entry
},
trailing: new Icon(Icons.edit),
);
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: new Scaffold(body: new ListView.builder(
itemBuilder: (context, entry) {
if (entry < _zerodayslist.length) {
return _buildRow(_zerodayslist[entry]);
} else
return new ListTile();
},
)),
floatingActionButton: _buildFAB(),
);
}
}
}

View file

@ -7,28 +7,21 @@ packages:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
version: "0.31.1"
version: "0.31.2-alpha.2"
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.2"
version: "1.4.3"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.6"
barback:
dependency: transitive
description:
name: barback
url: "https://pub.dartlang.org"
source: hosted
version: "0.15.2+15"
version: "2.0.7"
boolean_selector:
dependency: transitive
description:
@ -43,13 +36,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
cli_util:
dependency: transitive
description:
name: cli_util
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2+1"
collection:
dependency: transitive
description:
@ -70,14 +56,14 @@ packages:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2+1"
version: "2.0.3"
csslib:
dependency: transitive
description:
name: csslib
url: "https://pub.dartlang.org"
source: hosted
version: "0.14.1"
version: "0.14.3"
cupertino_icons:
dependency: "direct main"
description:
@ -101,7 +87,7 @@ packages:
name: front_end
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0-alpha.9"
version: "0.1.0-alpha.12"
glob:
dependency: transitive
description:
@ -136,7 +122,7 @@ packages:
name: http_parser
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.1"
version: "3.1.2"
intl:
dependency: "direct main"
description:
@ -151,13 +137,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.2+1"
isolate:
dependency: transitive
description:
name: isolate
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
js:
dependency: transitive
description:
@ -171,7 +150,7 @@ packages:
name: kernel
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0-alpha.9"
version: "0.3.0-alpha.12"
logging:
dependency: transitive
description:
@ -185,14 +164,14 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.1+4"
version: "0.12.2+1"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.2"
version: "1.1.5"
mime:
dependency: transitive
description:
@ -213,7 +192,7 @@ packages:
name: node_preamble
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.0"
version: "1.4.1"
package_config:
dependency: transitive
description:
@ -255,7 +234,7 @@ packages:
name: pub_semver
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.6"
version: "1.4.1"
quiver:
dependency: transitive
description:
@ -269,7 +248,7 @@ packages:
name: shelf
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.2"
version: "0.7.3"
shelf_packages_handler:
dependency: transitive
description:
@ -309,7 +288,7 @@ packages:
name: source_maps
url: "https://pub.dartlang.org"
source: hosted
version: "0.10.4"
version: "0.10.5"
source_span:
dependency: transitive
description:
@ -330,7 +309,7 @@ packages:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.4"
version: "1.6.6"
string_scanner:
dependency: transitive
description:
@ -351,7 +330,7 @@ packages:
name: test
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.34"
version: "0.12.37"
typed_data:
dependency: transitive
description:
@ -395,4 +374,4 @@ packages:
source: hosted
version: "2.1.13"
sdks:
dart: ">=2.0.0-dev.28.0 <=2.0.0-edge.af1436931b93e755d38223c487d33a0a1f5eadf5"
dart: ">=2.0.0-dev.52.0 <=2.0.0-edge.af1436931b93e755d38223c487d33a0a1f5eadf5"