Skip to content

[101] Complete #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Apr 6, 2018
Merged

[101] Complete #2

merged 17 commits into from
Apr 6, 2018

Conversation

willlarche
Copy link
Collaborator

Magic numbers and strings are for educational simplicity.

decoration: InputDecoration(
border: const UnderlineInputBorder(),
filled: true,
labelText: "Username",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, do we care if we use single vs. double quotes in the same file? You use them both in this file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, formatting. If you're using IntelliJ there should be a Tools -> Autoformat with dartfmt you can use, and map that to a keyboard shortcut.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran it! That's the way it did it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it may have a bug? Don't know. Fixed it tho.

],
),
),
SizedBox(height: 121.0),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought Material was about having heights/font sizes etc. in multiples of 4? E.g this would be 120.0 and the SizedBox below would be 12.0 or 16.0? This might be a team-specific guideline so feel free to ignore.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. My mocks were 121 but no need to bring attention to it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


import 'package:flutter/material.dart';

void main() => runApp(new ShrineApp());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove the new? (probably not on the tip of tree of Flutter due to flutter/flutter#15590 but theoretically, you should be?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Collaborator

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good start

padding: EdgeInsets.symmetric(horizontal: 24.0),
children: <Widget>[
SizedBox(height: 80.0),
Container(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This container isn't needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

SizedBox(height: 120.0),
TextField(
decoration: InputDecoration(
border: const UnderlineInputBorder(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the default, you don't need to specify it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

child: Text('NEXT'),
onPressed: () {
Navigator.pop(context);
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a trailing comma and then put the closing paren under the class name (same as everywhere else):

RaisedButton(
  child: Text('NEXT'),
  onPressed: () {
    Navigator.pop(context);
  },
),

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an extra indent here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That indent is coming from dartfmt. Think it could be somehow on purpose?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not know, however it's inconsistent with style in the Flutter codebase.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like my dartfmt was out of date. updating and rerunning.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

)
],
),
));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like things didn't fit, so you ended up with a '))' line, because there's an extra indent at the top?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

child: ListView(
padding: EdgeInsets.symmetric(horizontal: 24.0),
children: <Widget>[
SizedBox(height: 80.0),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these SizedBox instances being used to block out padding for the layout? If so, is that considered the correct way to do it, rather than wrapping the following Widget in Padding(padding: EdgeInsets.only(top:80.0))?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. I find that this style of inserting space between list items, where the gaps are defined explicitly with sized boxes, is easier to read than when the padding is part of the items themselves.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do either! I don't know what would be more expected. From an iOS POV, I wouldn't expect any of this to work without a bunch more layout code so my instincts don't apply.

title: 'Shrine',
home: HomePage(),
initialRoute: '/login',
onGenerateRoute: _getRoute,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another comment that's more a question:

Is there a definite benefit to using onGenerateRoute here rather than supplying a map via the routes property? It may just be the examples I happen to be looking at right now, but that seems like a popular option:

https://github.com/brianegan/flutter_architecture_samples/blob/master/example/scoped_model/lib/app.dart

I don't know that you can set the fullScreenDialog option that way, though, which may be a dealbreaker.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, I was not even aware of onGenerateRoute until now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's all new to me! Need me to change it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, actually, I used to have the routes map. But I couldn't get the pop to be a modal-style dismiss.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline, and this is definitely the better way to go. I'm now curious what other functionality you lose (if any) by using a straight up route table.

),
),
SizedBox(height: 32.0),
Row(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I'm using a ButtonBar here in my material example for the DevByte.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think I should? @HansMuller

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! I love it.

Copy link
Collaborator

@filiph filiph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with some nits

}

Route<dynamic> _getRoute(RouteSettings settings) {
if (settings.name == '/login') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Consider using the guard pattern here: if you can have a short (ideally one-line) if-else statement, use that instead of a longer if-else statement.

if (settings.name != '/login') return null;

return MaterialPageRoute<void>(
  ...
);

Of course, this depends. If you expect more routes, then the guard pattern would be silly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

title: 'Shrine',
home: HomePage(),
initialRoute: '/login',
onGenerateRoute: _getRoute,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, I was not even aware of onGenerateRoute until now.

@@ -0,0 +1,20 @@
import 'package:flutter/material.dart';

class HomePage extends StatefulWidget {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need stateful here, but I assume you know this.

There's a cool IDE feature in both IntelliJ and VS Code that lets you convert StatelessWidget to StatefulWidget with two keystrokes. You might want to teach this in the next step, because it's super helpful.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was because later I need it. But instead I'll take that moment to teach them, yeah.


import 'app.dart';

void main() => runApp(ShrineApp());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just FYI: optional new/const might not make it for I/O. That's a worst case scenario, but after the recent snafu, it's a lot more probable than before.

@@ -0,0 +1,21 @@
name: mdc_101_complete
description: Learn the basics of using Material Components by building a simple app with core components.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can stay inside width limit with

description: >
  Learn the basics of using Material Components by building a simple app 
  with core components.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

sdk: flutter


# The following section is specific to Flutter.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you already got rid of all the other comments, I think you can get rid of this one as well. (And the preceding blank line.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@willlarche willlarche mentioned this pull request Apr 5, 2018
title: 'Shrine',
home: HomePage(),
initialRoute: '/login',
onGenerateRoute: _getRoute,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline, and this is definitely the better way to go. I'm now curious what other functionality you lose (if any) by using a straight up route table.

@willlarche willlarche merged commit b4ada31 into material-components:master Apr 6, 2018
@willlarche willlarche deleted the feature-101-complete branch April 6, 2018 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants