diff --git a/README.md b/README.md index 20eed45..a628a7f 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,3 @@ # destinations An app built using Flutter and Firebase - -## Getting Started - -This project is a starting point for a Flutter application. - -A few resources to get you started if this is your first Flutter project: - -- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab) -- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook) - -For help getting started with Flutter, view our -[online documentation](https://flutter.dev/docs), which offers tutorials, -samples, guidance on mobile development, and a full API reference. diff --git a/lib/destinationpage.dart b/lib/destinationpage.dart new file mode 100644 index 0000000..39da797 --- /dev/null +++ b/lib/destinationpage.dart @@ -0,0 +1,70 @@ +// Copyright 2018 The Flutter team. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:english_words/english_words.dart'; +import 'main.dart'; + +class DestinationPage extends StatefulWidget { + const DestinationPage({Key? key, required this.title}) : super(key: key); + final String title; + + @override + _DestinationPageState createState() => _DestinationPageState(); +} + + +//means that this class is a subclass which inherits State and is of type - instead of Generic type T +class _DestinationPageState extends State { + final _suggestions = []; + final _biggerFont = const TextStyle(fontSize: 18.0); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + //wrapped in sub-widget Text + title: Text(widget.title), + ), + body: _buildSuggestions(), + ); + } + + //builds ListView widget + Widget _buildSuggestions() { + return ListView.builder( + padding: const EdgeInsets.all(16.0), + itemBuilder: /*1*/ (context, i) { + if (i.isOdd) return const Divider(); /*2*/ + + final index = i ~/ 2; /*3*/ + if (index >= _suggestions.length) { + _suggestions.addAll(generateWordPairs().take(10)); /*4*/ + } + return _buildRow(_suggestions[index]); + }); + } + + //used to build each row (list tile) + Widget _buildRow(WordPair pair) { + return ListTile( + title: Text( + pair.asPascalCase, + style: _biggerFont, + ), + trailing: Icon(Icons.add + ), + onTap: () { // NEW lines from here... + setState(() { + //Creats a new instance of homepage: v bad change later + Navigator.push( + context, + MaterialPageRoute(builder: (context) => MyHomePage(title: 'Home')), + ); + }); + }, + ); + } +} + diff --git a/lib/main.dart b/lib/main.dart index b9bfc38..e0b9052 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'destinationpage.dart'; void main() { runApp(MyApp()); @@ -56,6 +57,10 @@ class _MyHomePageState extends State { // _counter without calling setState(), then the build method would not be // called again, and so nothing would appear to happen. _counter++; + Navigator.push( + context, + MaterialPageRoute(builder: (context) => DestinationPage(title: 'Saved Destinations')), + ); }); } @@ -93,6 +98,9 @@ class _MyHomePageState extends State { // horizontal). mainAxisAlignment: MainAxisAlignment.center, children: [ + Text( + 'Click the button to see your saved destinations', + ), Text( 'You have pushed the button this many times:', ), @@ -106,7 +114,7 @@ class _MyHomePageState extends State { floatingActionButton: FloatingActionButton( onPressed: _incrementCounter, tooltip: 'Increment', - child: Icon(Icons.add), + child: Icon(Icons.arrow_forward), ), // This trailing comma makes auto-formatting nicer for build methods. ); } diff --git a/pubspec.lock b/pubspec.lock index 4670f02..5043147 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -71,6 +71,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.3" + english_words: + dependency: "direct main" + description: + name: english_words + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.0" fake_async: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 336a431..009b46f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -27,7 +27,7 @@ dependencies: cloud_firestore: ^1.0.0 # new firebase_auth: ^1.0.0 # new provider: ^5.0.0 # new - + english_words: ^4.0.0 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. @@ -36,7 +36,7 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - + english_words: ^4.0.0 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec