Skip to content

Commit

Permalink
Finished implementation of FullScreenDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinusX committed Aug 15, 2017
1 parent 094a13a commit 82c068a
Show file tree
Hide file tree
Showing 8 changed files with 374 additions and 306 deletions.
47 changes: 0 additions & 47 deletions lib/WeightListItem.dart

This file was deleted.

242 changes: 0 additions & 242 deletions lib/add_entry_dialog.dart

This file was deleted.

48 changes: 39 additions & 9 deletions lib/HomePage.dart → lib/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:weight_tracker/WeightListItem.dart';
import 'package:weight_tracker/add_entry_dialog.dart';
import 'package:weight_tracker/model/WeightSave.dart';
import 'package:weight_tracker/model/weight_entry.dart';
import 'package:weight_tracker/weight_entry_dialog.dart';
import 'package:weight_tracker/weight_list_item.dart';

class HomePage extends StatefulWidget {
HomePage({Key key, this.title}) : super(key: key);
Expand All @@ -14,7 +14,9 @@ class HomePage extends StatefulWidget {
}

class _HomePageState extends State<HomePage> {
List<WeightSave> weightSaves = new List();
List<WeightEntry> weightSaves = new List();
ScrollController _listViewScrollController = new ScrollController();
double _itemExtent = 50.0;

@override
Widget build(BuildContext context) {
Expand All @@ -23,13 +25,18 @@ class _HomePageState extends State<HomePage> {
title: new Text(widget.title),
),
body: new ListView.builder(
shrinkWrap: true,
reverse: true,
controller: _listViewScrollController,
itemCount: weightSaves.length,
itemBuilder: (buildContext, index) {
//calculating difference
double difference = index == 0
? 0.0
: weightSaves[index].weight - weightSaves[index - 1].weight;
return new WeightListItem(weightSaves[index], difference);
return new InkWell(
onTap: () => _editEntry(weightSaves[index]),
child: new WeightListItem(weightSaves[index], difference));
},
),
floatingActionButton: new FloatingActionButton(
Expand All @@ -40,17 +47,40 @@ class _HomePageState extends State<HomePage> {
);
}

void _addWeightSave(WeightSave weightSave) {
void _addWeightSave(WeightEntry weightSave) {
setState(() {
weightSaves.add(weightSave);
_listViewScrollController.animateTo(
weightSaves.length * _itemExtent,
duration: const Duration(microseconds: 1),
curve: new ElasticInCurve(0.01),
);
});
}

_editEntry(WeightEntry weightSave) {
Navigator
.of(context)
.push(
new MaterialPageRoute<WeightEntry>(
builder: (BuildContext context) {
return new WeightEntryDialog.edit(weightSave);
},
fullscreenDialog: true,
),
)
.then((newSave) {
if (newSave != null) {
setState(() => weightSaves[weightSaves.indexOf(weightSave)] = newSave);
}
});
}

Future _openAddEntryDialog() async {
WeightSave save =
await Navigator.of(context).push(new MaterialPageRoute<WeightSave>(
WeightEntry save =
await Navigator.of(context).push(new MaterialPageRoute<WeightEntry>(
builder: (BuildContext context) {
return new AddEntryDialog.add(
return new WeightEntryDialog.add(
weightSaves.isNotEmpty ? weightSaves.last.weight : 60.0);
},
fullscreenDialog: true));
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:weight_tracker/HomePage.dart';
import 'package:weight_tracker/home_page.dart';


void main() {
Expand Down
7 changes: 0 additions & 7 deletions lib/model/WeightSave.dart

This file was deleted.

Loading

0 comments on commit 82c068a

Please sign in to comment.