open_weather_map_client 0.0.7 copy "open_weather_map_client: ^0.0.7" to clipboard
open_weather_map_client: ^0.0.7 copied to clipboard

outdated

Package that communicates with Open Weather Map to obtain climate data in a model.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:open_weather_map_client/open_weather_map_client.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: _HomePage(),
    );
  }
}

class _HomePage extends StatelessWidget {
  _HomePage({Key? key}) : super(key: key);

  // Define the OpenWeatherMap class to connect wit API.
  final OpenWeatherMap openWeatherMap = OpenWeatherMap(
    apiKey: '856822fd8e22db5e1ba48c0e7d69844a',
  );

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.teal,
        title: const Text('Weather'),
        centerTitle: true,
      ),
      body: Container(
        color: Colors.amber,
        child: Center(
          child: FutureBuilder<Weather>(
            future: openWeatherMap.currentWeatherByCity(name: 'London'),
            builder: (context, snapshot) {
              if (snapshot.connectionState == ConnectionState.waiting) {
                return const Center(
                  child: CircularProgressIndicator.adaptive(),
                );
              }
              return SizedBox(
                width: 400,
                height: 400,
                child: Card(
                  margin: const EdgeInsets.all(8.0),
                  child: Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        Text(
                          'Country:\n${openWeatherMap.detailedCity?.country?.name}',
                        ),
                        const Divider(),
                        Text('City: ${openWeatherMap.detailedCity?.name}'),
                        const Divider(),
                        Text(
                          'Description: ${snapshot.data!.description}',
                        ),
                        const Divider(),
                        Text(
                          'Temperature: ${snapshot.data!.temperature.toString()}',
                        ),
                      ],
                    ),
                  ),
                ),
              );
            },
          ),
        ),
      ),
    );
  }
}
3
likes
0
pub points
45%
popularity

Publisher

verified publisheralexastudillo.com

Package that communicates with Open Weather Map to obtain climate data in a model.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, http

More

Packages that depend on open_weather_map_client