Skip to content

Commit

Permalink
Round temperature to nearest integer, capitalize first letter of each…
Browse files Browse the repository at this point in the history
… word.
  • Loading branch information
fwrhine committed Nov 22, 2020
1 parent 6071250 commit 2df47d2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:http/http.dart' as http;
import 'package:strings/strings.dart';
import 'dart:convert';

String apiKey = "your API key here";
String apiKey = "142286faa5bd8ccf1ae8df60bef70179";

void main () => runApp(
MaterialApp(
Expand Down Expand Up @@ -70,7 +71,7 @@ class _HomeState extends State<Home> {
),
),
Text(
temp != null ? temp.toString() + "\u00B0C" : "Loading",
temp != null ? (temp.toInt().round()).toString() + "\u00B0C" : "Loading",
style: TextStyle(
color: Colors.white,
fontSize: 40.0,
Expand Down Expand Up @@ -99,12 +100,12 @@ class _HomeState extends State<Home> {
ListTile(
leading: FaIcon(FontAwesomeIcons.thermometerHalf),
title: Text("Temperature"),
trailing: Text(temp != null ? temp.toString() + "\u00B0C" : "Loading"),
trailing: Text(temp != null ? (temp.toInt().round()).toString() + "\u00B0C" : "Loading"),
),
ListTile(
leading: FaIcon(FontAwesomeIcons.cloud),
title: Text("Weather"),
trailing: Text(description != null ? description.toString() : "Loading"),
trailing: Text(description != null ? description.toString().capitalizeFirstofEach : "Loading"),
),
ListTile(
leading: FaIcon(FontAwesomeIcons.sun),
Expand All @@ -124,4 +125,8 @@ class _HomeState extends State<Home> {
)
);
}
}

extension CapExtension on String {
String get capitalizeFirstofEach => this.split(" ").map((str) => capitalize(str)).join(" ");
}
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies:
cupertino_icons: ^1.0.0
font_awesome_flutter: ^8.10.0
http: ^0.12.2
strings: ^0.1.4

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 2df47d2

Please sign in to comment.