Compare commits
3 Commits
ee116bed8d
...
c2537f78cd
Author | SHA1 | Date | |
---|---|---|---|
c2537f78cd | |||
b598f4cddb | |||
8cc609ff4e |
3
.gitignore
vendored
3
.gitignore
vendored
@ -242,3 +242,6 @@ app.*.map.json
|
|||||||
/android/app/debug
|
/android/app/debug
|
||||||
/android/app/profile
|
/android/app/profile
|
||||||
/android/app/release
|
/android/app/release
|
||||||
|
|
||||||
|
# Do not post secrets!
|
||||||
|
secrets.dart
|
||||||
|
3
bin/build.sh
Normal file
3
bin/build.sh
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# TODO / TBD
|
3
bin/run.sh
Executable file
3
bin/run.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
flutter run -d chrome
|
3
bin/test.sh
Executable file
3
bin/test.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
flutter run -d linux
|
@ -1,20 +1,87 @@
|
|||||||
|
// Local
|
||||||
|
import 'package:com_hyperling_buddy_website/secrets.dart';
|
||||||
|
|
||||||
|
// Flutter / Dart
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const MainApp());
|
runApp(const MainApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
class MainApp extends StatelessWidget {
|
final String loadText = "Loading...";
|
||||||
|
|
||||||
|
class MainApp extends StatefulWidget {
|
||||||
const MainApp({super.key});
|
const MainApp({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<MainApp> createState() => _MainAppState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MainAppState extends State<MainApp> {
|
||||||
|
String weather = loadText;
|
||||||
|
bool keepLoading = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_callOpenWeather();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
weather = loadText;
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return const MaterialApp(
|
if (weather == loadText) {
|
||||||
|
Future.delayed(Duration(seconds: 1), () {
|
||||||
|
setState(() {
|
||||||
|
keepLoading = true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return MaterialApp(
|
||||||
home: Scaffold(
|
home: Scaffold(
|
||||||
body: Center(
|
body: Center(
|
||||||
child: Text('Hello World!'),
|
child: Column(children: [Text('Hello World!'), Text(weather)]),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// How to guide:
|
||||||
|
// https://openweathermap.org/current#zip
|
||||||
|
Future<String> _hitOpenWeather(String zipCode, String? countryCode) async {
|
||||||
|
countryCode ??= "US";
|
||||||
|
|
||||||
|
http.Response response = await http.get(
|
||||||
|
Uri.parse(
|
||||||
|
'https://api.openweathermap.org/data/2.5/forecast'
|
||||||
|
'?zip=$zipCode,$countryCode'
|
||||||
|
'&units=imperial'
|
||||||
|
'&appid=$openWeatherKey',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
String data = "";
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
data = response.body;
|
||||||
|
var decodedData = jsonDecode(data);
|
||||||
|
print(decodedData);
|
||||||
|
data = decodedData.toString();
|
||||||
|
} else {
|
||||||
|
print(response.statusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
_callOpenWeather() async {
|
||||||
|
weather = await _hitOpenWeather("47630", "US");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
3
lib/secrets.dart.EXAMPLE
Normal file
3
lib/secrets.dart.EXAMPLE
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
// This file needs renamed `secrets.dart` and filled out properly if implemented.
|
||||||
|
|
||||||
|
final openWeatherKey = "abc123";
|
@ -1,5 +1,5 @@
|
|||||||
name: com_hyperling_buddy_website
|
name: com_hyperling_buddy_website
|
||||||
description: "A new Flutter project."
|
description: "Buddy, a weather-focused API frontend."
|
||||||
publish_to: 'none'
|
publish_to: 'none'
|
||||||
version: 0.1.0
|
version: 0.1.0
|
||||||
|
|
||||||
@ -9,6 +9,7 @@ environment:
|
|||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
http: ^1.3.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
Reference in New Issue
Block a user