forked from flutter/udacity-course
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add code snippets from screencasts * Adds Cupertino/Material demo * add copyright headers * add colors demo * add colors demo * add demo code * Remove extra newline * add orientation code * clean up code * 2 spaces
- Loading branch information
Showing
6 changed files
with
262 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2018 The Chromium Authors. 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'; | ||
|
||
void main() { | ||
runApp(MaterialApp( | ||
debugShowCheckedModeBanner: false, | ||
title: 'Hello Rectangle', | ||
home: Scaffold( | ||
body: HelloRectangle(), | ||
), | ||
)); | ||
} | ||
|
||
class HelloRectangle extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
var container = Container( | ||
color: Colors.purple, | ||
); | ||
return Container( | ||
padding: EdgeInsets.only( | ||
top: 64.0, | ||
left: 32.0, | ||
bottom: 32.0, | ||
right: 32.0, | ||
), | ||
child: container, | ||
); | ||
} | ||
} | ||
|
||
/// Example of a widget with the `children` property. | ||
var container = Column( | ||
children: <Widget>[ | ||
Text('Hello!'), | ||
Text('Hello!'), | ||
Text('Hello!'), | ||
Text('Hello!'), | ||
], | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// To keep your imports tidy, follow the ordering guidelines at | ||
// https://www.dartlang.org/guides/language/effective-dart/style#ordering | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:unit_converter/converter_route.dart'; | ||
import 'package:unit_converter/unit.dart'; | ||
|
||
// We use an underscore to indicate that these variables are private. | ||
// See https://www.dartlang.org/guides/language/effective-dart/design#libraries | ||
final _rowHeight = 100.0; | ||
final _borderRadius = BorderRadius.circular(_rowHeight / 2); | ||
|
||
/// A [Category] for a list of [Unit]s. | ||
class Category extends StatelessWidget { | ||
final String name; | ||
final List<Unit> units; | ||
final ColorSwatch color; | ||
final String iconLocation; | ||
|
||
/// Constructor. | ||
const Category({ | ||
Key key, | ||
this.name, | ||
this.units, | ||
this.color, | ||
this.iconLocation, | ||
}) : super(key: key); | ||
|
||
/// Navigates to the [ConverterRoute]. | ||
void _navigateToConverter(BuildContext context) { | ||
if (Navigator.of(context).canPop()) { | ||
Navigator.of(context).pop(); | ||
} | ||
Navigator.of(context).push(MaterialPageRoute<Null>( | ||
builder: (BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
elevation: 1.0, | ||
title: Text( | ||
name, | ||
style: Theme.of(context).textTheme.display1, | ||
), | ||
centerTitle: true, | ||
backgroundColor: color[100], | ||
), | ||
body: ConverterRoute( | ||
name: name, | ||
units: units, | ||
color: color, | ||
), | ||
// This prevents the onscreen keyboard from affecting the size of the | ||
// screen, and the space given to widgets. | ||
// See https://docs.flutter.io/flutter/material/Scaffold/resizeToAvoidBottomPadding.html | ||
resizeToAvoidBottomPadding: false, | ||
); | ||
}, | ||
)); | ||
} | ||
|
||
/// Builds a widget that shows [Category] information, using [ListTile] | ||
Widget build(BuildContext context) { | ||
assert(debugCheckHasMaterial(context)); | ||
return Material( | ||
color: Colors.green[100], | ||
child: ListTile( | ||
leading: iconLocation != null ? Image.asset(iconLocation) : null, | ||
title: Text( | ||
name, | ||
style: Theme.of(context).textTheme.display1.copyWith( | ||
color: Colors.black, | ||
fontSize: 24.0, | ||
), | ||
), | ||
onTap: () => _navigateToConverter(context), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'dart:math'; | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
void main() { | ||
runApp( | ||
MaterialApp( | ||
home: Scaffold( | ||
appBar: AppBar( | ||
title: Text('Hello Rainbow Rectangle'), | ||
), | ||
body: HelloRectangle(text: 'Hello from instantiation!'), | ||
), | ||
), | ||
); | ||
} | ||
|
||
class HelloRectangle extends StatefulWidget { | ||
final String text; | ||
|
||
HelloRectangle({ | ||
this.text, | ||
}); | ||
|
||
@override | ||
createState() => _HelloRectangleState(); | ||
} | ||
|
||
class _HelloRectangleState extends State<HelloRectangle> { | ||
Color _color = Colors.greenAccent; | ||
|
||
void _generateRandomColor() { | ||
var random = Random(); | ||
setState(() { | ||
_color = Color.fromARGB( | ||
255, | ||
random.nextInt(255), | ||
random.nextInt(255), | ||
random.nextInt(255), | ||
); | ||
}); | ||
} | ||
|
||
Widget build(BuildContext context) { | ||
return Center( | ||
child: FlatButton( | ||
onPressed: _generateRandomColor, | ||
color: _color, | ||
child: Center( | ||
child: Text( | ||
widget.text, | ||
style: TextStyle(fontSize: 40.0), | ||
textAlign: TextAlign.center, | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2018 The Chromium Authors. 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:flutter/cupertino.dart'; | ||
|
||
void main() { | ||
runApp( | ||
MaterialApp( | ||
debugShowCheckedModeBanner: false, | ||
home: Scaffold( | ||
appBar: AppBar( | ||
title: Text('Hello Switch'), | ||
), | ||
body: HelloSwitch(), | ||
), | ||
), | ||
); | ||
} | ||
|
||
class HelloSwitch extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Center( | ||
child: Row( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: <Widget>[ | ||
Text( | ||
'Hello!', | ||
style: TextStyle(fontSize: 36.0), | ||
), | ||
Theme.of(context).platform == TargetPlatform.iOS | ||
? CupertinoSwitch( | ||
value: true, | ||
onChanged: (bool toggled) {}, | ||
) | ||
: Switch( | ||
value: true, | ||
onChanged: (bool toggled) {}, | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters