Skip to content

Instantly share code, notes, and snippets.

@tanabe1478
Created February 12, 2020 13:16
Show Gist options
  • Select an option

  • Save tanabe1478/bf4eb518952e75cdf42ba932368d2346 to your computer and use it in GitHub Desktop.

Select an option

Save tanabe1478/bf4eb518952e75cdf42ba932368d2346 to your computer and use it in GitHub Desktop.
Quiz: Code the Unit Converter AppBar and Category Routeの回答
// 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';
// TODO: Check if we need to import anything
import 'package:task_03_category_route/category.dart';
// TODO: Define any constants
/// Category Route (screen).
///
/// This is the 'home' screen of the Unit Converter. It shows a header and
/// a list of [Categories].
///
/// While it is named CategoryRoute, a more apt name would be CategoryScreen,
/// because it is responsible for the UI at the route's destination.
class CategoryRoute extends StatelessWidget {
const CategoryRoute();
static const _categoryNames = <String>[
'Length',
'Area',
'Volume',
'Mass',
'Time',
'Digital Storage',
'Energy',
'Currency',
];
static const _baseColors = <Color>[
Colors.teal,
Colors.orange,
Colors.pinkAccent,
Colors.blueAccent,
Colors.yellow,
Colors.greenAccent,
Colors.purpleAccent,
Colors.red,
];
@override
Widget build(BuildContext context) {
// TODO: Create a list of the eight Categories, using the names and colors
// from above. Use a placeholder icon, such as `Icons.cake` for each
// Category. We'll add custom icons later.
var categories = List<Category>.generate(
_categoryNames.length,
(i) => Category(
name: _categoryNames[i],
iconLocation: Icons.cake,
color: _baseColors[i],
),
);
// TODO: Create a list view of the Categories
final listView = ListView.builder(
itemCount: categories.length,
itemBuilder: (context, index) {
return categories[index];
},
);
// TODO: Create an App Bar
final appBar = AppBar(
backgroundColor: Colors.lightGreenAccent,
title: Text(
'Unit Converter',
style: TextStyle(color: Colors.black, fontSize: 25.0),
),
);
return Scaffold(
appBar: appBar,
body: listView,
);
}
}
// 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.
// You can read about packages here: https://flutter.io/using-packages/
import 'package:flutter/material.dart';
// TODO: Import the CategoryRoute widget
import 'package:task_03_category_route/category_route.dart';
/// The function that is called when main.dart is run.
void main() {
runApp(UnitConverterApp());
}
/// This widget is the root of our application.
///
/// The first screen we see is a list [Categories].
class UnitConverterApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Unit Converter',
// TODO: Instead of pointing to exactly 1 Category widget,
// our home should now point to an instance of the CategoryRoute widget.
home: CategoryRoute()
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment