Home > front end >  Flutter: Missing concrete implementation of 'State.build'
Flutter: Missing concrete implementation of 'State.build'

Time:03-30

I am receiving an error on line 16 : class _HomePageState extends State {

I have a build function already in a widget that I have posted below, and when I try to implement a build in the _HomePageState the code below is unable to run. Im unsure on how to fix this error and would appreciate any help!

import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

void main() => runApp(MaterialApp(
      home: HomePage(),
      debugShowCheckedModeBanner: false,
    ));

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

 class _HomePageState extends State<HomePage> {
   Future getUserData() async {
    var response = await http.get(Uri.parse(
    'https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&hourly=temperature_2m'));

var jsonData = jsonDecode(response.body);

    List users = (response.body as List?)
            ?.map((u) => User(
                u['hourly'],
                u['time'],
                u['temperature_2m'],
                u['longitude'],
                u['generationtime_ms'],
                u['hourly_units'],
                u['latitude']))
            .toList() ??
        [];
  }
}

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: const Text('Rangers Tool'),
    ),
    body: Center(
        child: Card(
            child: FutureBuilder(
      future: getUserData(),
      builder: (context, AsyncSnapshot snapshot) {
        if (!snapshot.hasData) {
          return const Center(child:        

    CircularProgressIndicator());
        } else {
          return ListView.builder(
              itemCount: snapshot.data?.length,
              itemBuilder: (context, i) {
                return ListTile(
                  title: Text(snapshot.data[i].longitude),
                  subtitle: Text(snapshot.data[i].latitude),
                );
              });
        }
      },
    ))),
  );
}

getUserData() {}

class User {
  final String? hourly,
      time,
      temperature_2m,
      longitude,
      generationtime_m,
      hourly_units,
      latitude;

  User(this.longitude, this.latitude, this.hourly, this.time,
      this.temperature_2m, this.generationtime_m, this.hourly_units);
}

CodePudding user response:

Your build method is outside the scope of your state class.

  • Related