GithubHelp home page GithubHelp logo

Comments (18)

RIP321 avatar RIP321 commented on July 20, 2024 46

Hi AdalWay I've found a solution instead of using future void in class network helper just use future.

As the function is returning a value so we cannot assign future.

I've no idea how did it work in the video of the tutor.

from clima-flutter.

tamersolieman avatar tamersolieman commented on July 20, 2024 2

Hi AdalWay I've found a solution instead of using future void in class network helper just use future.

As the function is returning a value so we cannot assign future.

I've no idea how did it work in the video of the tutor.

This solution works with me.
Thanks @RIP321

from clima-flutter.

AbuTawhidRian avatar AbuTawhidRian commented on July 20, 2024 2

I've found a solution instead of using future void in class network helper just use future.

import 'package:http/http.dart' as http;
import 'dart:convert';

class Networking {
Networking(this.url);
final String url;

Future getData() async {
http.Response response = await http.get(Uri.parse(url));
if (response.statusCode == 200) {
String data = response.body;
return jsonDecode(data);
} else {
print(response.statusCode);
}
}
}

from clima-flutter.

DeStefaniAndrei avatar DeStefaniAndrei commented on July 20, 2024 1

Thx so much, to anyone who didn't understand it's the getData function which Angela made us Future, but since it the JsonDecode(data), which we have set weatherData to which we are trying to make it the location screen input, is being returned, so it's only Future, not Future

from clima-flutter.

AvinandanBose avatar AvinandanBose commented on July 20, 2024 1

Hi AdalWay I've found a solution instead of using future void in class network helper just use future.

As the function is returning a value so we cannot assign future.

I've no idea how did it work in the video of the tutor.

Use :

Future<dynamic> getLocation() async {
    Location location = Location();
    await location.getCurrentLocation();
    latitude = location.latitude;
    longitude = location.longitude;
    NetworkHelper networkHelper = NetworkHelper('https://api.openweathermap.org/data/2.5/weather?lat=$latitude&lon=$longitude&appid=$apiKey');
    var  weatherData = await networkHelper.getData();
    Navigator.push(context, MaterialPageRoute(
      builder: (context){
        return LocationScreen(locationWeather:weatherData,);
    },
    ),
    );
  }

Then:

class NetworkHelper{
  final String url;
  NetworkHelper(this.url);
  Future<dynamic> getData() async {
    http.Response response = await http.get(Uri.parse(url));
    if(response.statusCode == 200) {
      String data = response.body;
      dynamic decodeData = jsonDecode(data);
      return decodeData;
    }
    else{
      print(response.statusCode);
    }

Actually you are using var datatype assigning a void i.e. Future<void> to WeatherData while it will be dynamic . Thats the problem.

from clima-flutter.

AdalWay avatar AdalWay commented on July 20, 2024

Im having issues with same problem...

from clima-flutter.

techno-disaster avatar techno-disaster commented on July 20, 2024

In NetworkHelper as you are returning something it cant be void

from clima-flutter.

AvinashMahanthi avatar AvinashMahanthi commented on July 20, 2024

Hi AdalWay I've found a solution instead of using future void in class network helper just use future.

As the function is returning a value so we cannot assign future.

I've no idea how did it work in the video of the tutor.

Yah this also works for me thanks @RIP321

from clima-flutter.

shaishalevss avatar shaishalevss commented on July 20, 2024

Same problem... I ran into a different problem when I remove the from my Future function in the networking:
the new problem is:
No constructor 'LocationScreen.' with matching arguments declared in class 'LocationScreen'.
Receiver: LocationScreen
Tried calling: new LocationScreen.()
Found: new LocationScreen.(dynamic, {_Location $creationLocationd_0dea112b090073317d4}) => LocationScreen

from clima-flutter.

RIP321 avatar RIP321 commented on July 20, 2024

Same problem... I ran into a different problem when I remove the from my Future function in the networking:
the new problem is:
No constructor 'LocationScreen.' with matching arguments declared in class 'LocationScreen'. Receiver: LocationScreen Tried calling: new LocationScreen.() Found: new LocationScreen.(dynamic, {_Location $creationLocationd_0dea112b090073317d4}) => LocationScreen

Share your code

from clima-flutter.

furquan786 avatar furquan786 commented on July 20, 2024

i have also same problem "error: This expression has a type of 'void' so its value can't be used. (use_of_void_result at [clima] lib\screens\loading_screen.dart:38)"
please help me...

from clima-flutter.

AvinashMahanthi avatar AvinashMahanthi commented on July 20, 2024

i have also same problem "error: This expression has a type of 'void' so its value can't be used. (use_of_void_result at [clima] lib\screens\loading_screen.dart:38)"
please help me...

Please share your code

from clima-flutter.

FredWolfe avatar FredWolfe commented on July 20, 2024

Im having issues with same problem...

me too

from clima-flutter.

AslanDevbrat avatar AslanDevbrat commented on July 20, 2024

Hi AdalWay I've found a solution instead of using future void in class network helper just use future.

As the function is returning a value so we cannot assign future.

I've no idea how did it work in the video of the tutor.

That helped me

from clima-flutter.

malikdanishalii avatar malikdanishalii commented on July 20, 2024

i have also same problem.

from clima-flutter.

malikdanishalii avatar malikdanishalii commented on July 20, 2024

The error resolved by running the application on real / physical devices because emulator or simulator has the problem of getting real time location as per my knowledge and understanding after working for three days on this issue.

from clima-flutter.

robfrei avatar robfrei commented on July 20, 2024

Screenshot 2022-11-16 at 7 57 56 PM

from clima-flutter.

maheenqayyum avatar maheenqayyum commented on July 20, 2024

import 'package:audioplayers/audioplayers.dart';
import 'package:downloader/components/custom_list_tile.dart';
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
const MyApp({super.key});

// This widget is the root of your application.
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: MusicApp(),
);
}
}

class MusicApp extends StatefulWidget {
const MusicApp({Key? key}) : super(key: key);

@OverRide
State createState() => _MusicAppState();
}

class _MusicAppState extends State {

List musicList = [
{
'title': "Tech House Vibes",
'singer': "Alejandro Magana",
'url': "https://assets.mixkit.co/music/preview/mixkit-tech-house-vibes-130.mp3",
'coverUrl': "https://images.unsplash.com/photo-1546521677-b3a9b11bee6f?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTB8fGNvdmVyfGVufDB8fDB8fHww&auto=format&fit=crop&w=500&q=60"
},
{
'title': "Hazy After Hours",
'singer': "Alejandro Magana",
'url': "https://assets.mixkit.co/music/preview/mixkit-hazy-after-hours-132.mp3",
'coverUrl': "https://images.unsplash.com/photo-1546521677-b3a9b11bee6f?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTB8fGNvdmVyfGVufDB8fDB8fHww&auto=format&fit=crop&w=500&q=60"
},
{
'title': "Hip Hop 02",
'singer': "Lily J",
'url': "https://assets.mixkit.co/music/preview/mixkit-hip-hop-02-738.mp3",
'coverUrl': "https://images.unsplash.com/photo-1546521677-b3a9b11bee6f?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTB8fGNvdmVyfGVufDB8fDB8fHww&auto=format&fit=crop&w=500&q=60"
},
{
'title': "A Very Happy Christmas",
'singer': "Michael Ramir C",
'url': "https://assets.mixkit.co/music/preview/mixkit-a-very-happy-christmas-897.mp3",
'coverUrl': "https://images.unsplash.com/photo-1546521677-b3a9b11bee6f?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTB8fGNvdmVyfGVufDB8fDB8fHww&auto=format&fit=crop&w=500&q=60"
},
// {
// 'title': "Sun and His Daughter",
// 'singer': "Eugenio Mininni",
// 'url': "https://assets.mixkit.co/music/preview/mixkit-sun-and-his-daughter-580.mp3",
// 'coverUrl': "https://images.unsplash.com/photo-1546521677-b3a9b11bee6f?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTB8fGNvdmVyfGVufDB8fDB8fHww&auto=format&fit=crop&w=500&q=60"
// },
// {
// 'title': "Raising Me Higher",
// 'singer': "Ahjay Stelino",
// 'url': "https://assets.mixkit.co/music/preview/mixkit-sun-and-his-daughter-580.mp3",
// 'coverUrl': "https://images.unsplash.com/photo-1546521677-b3a9b11bee6f?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTB8fGNvdmVyfGVufDB8fDB8fHww&auto=format&fit=crop&w=500&q=60"
// },
// {
// 'title': "Life is a Dream",
// 'singer': "Michael Ramir C",
// 'url': "https://assets.mixkit.co/music/preview/mixkit-life-is-a-dream-837.mp3",
// 'coverUrl': "https://images.unsplash.com/photo-1546521677-b3a9b11bee6f?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTB8fGNvdmVyfGVufDB8fDB8fHww&auto=format&fit=crop&w=500&q=60"
// },
// {
// 'title': "Driving Ambition",
// 'singer': "Ahjay Stelino",
// 'url': "https://assets.mixkit.co/music/preview/mixkit-driving-ambition-32.mp3",
// 'coverUrl': "https://images.unsplash.com/photo-1546521677-b3a9b11bee6f?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTB8fGNvdmVyfGVufDB8fDB8fHww&auto=format&fit=crop&w=500&q=60"
// },
];

String currentTitle = "";
String currentCover = "";
String currentSinger = "";
IconData btnIcon = Icons.play_arrow;

AudioPlayer audioPlayer = new AudioPlayer();
bool isPlaying = false;
String currentSong = "";

Duration duration = new Duration();
Duration position = new Duration();

void playMusic(String url) async {
if(isPlaying && currentSong != url){
audioPlayer.pause();
int result = await audioPlayer.play(url);
if(result == 1){
setState(() {
currentSong = url;
});
}
} else if(!isPlaying){
int result = await audioPlayer.play(url);
if(result == 1){
setState(() {
isPlaying = true;
});
}
}
audioPlayer.onDurationChanged.listen((event) {
setState(() {
duration = event;
});
});

audioPlayer.onPositionChanged.listen((event) {
  setState(() {
    position = event;
  });
});

}

@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
title: Text("My Playlist",
style: TextStyle(
color: Colors.black
),
),
elevation: 0,
),
body: Column(
children: [
//The app is composed of 2 parts
//The first one is the song playlist

      Expanded(
          child: ListView.builder(
              itemCount: musicList.length,
              itemBuilder: (context, index) =>
                customListTile(
                    onTap: (){
                      playMusic(musicList[index]['url']);
                      setState(() {
                        currentTitle = musicList[index]['title'];
                        currentCover = musicList[index]['coverUrl'];
                        currentSinger = musicList[index]['singer'];
                      });
                    },
                    title: musicList[index]['title'],
                    singer: musicList[index]['singer'],
                    cover: musicList[index]['coverUrl']
          )
          ),
      ),
      //The second one is the player
      Container(
        decoration: BoxDecoration(
          color: Colors.white,
          boxShadow: [
            BoxShadow(
              color: Color(0x55212121),
              blurRadius: 8
            )
          ]
      ),
        child: Column(
          children: [
            Slider.adaptive(
                value: position.inSeconds.toDouble(),
                min: 0,
                max: duration.inSeconds.toDouble(),
                onChanged: (value) {},
            ),
            Padding(
              padding: const EdgeInsets.only
                (left: 8, right: 8, bottom: 8),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  Container(
                    height: 60,
                    width: 60,
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(6),
                        image: DecorationImage(
                            image: NetworkImage(currentCover))
                    ),
                  ),
                  SizedBox(width: 10),
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                            currentTitle,
                            style: TextStyle(
                                fontSize: 18,
                                fontWeight: FontWeight.w600)
                        ),
                        SizedBox(height: 5),
                        Text(
                          currentSinger,
                          style: TextStyle(
                              color: Colors.grey,
                              fontSize: 14
                          ),
                        )
                      ],
                    ),
                  ),
                  IconButton(
                      onPressed: (){
                        if(isPlaying){
                          audioPlayer.pause();
                          setState(() {
                            btnIcon = Icons.pause;
                            isPlaying = false;
                          });
                        } else {
                          audioPlayer.resume();
                          setState(() {
                            btnIcon = Icons.play_arrow;
                            isPlaying = true;
                          });
                        }
                      },
                      iconSize: 42,
                      icon: Icon(btnIcon))
                ],
              ),
            )
          ],
        ),
      )
    ],
  ),
);

}
}

lib/main.dart:106:43: Error: The argument type 'String' can't be assigned to the parameter type 'Source'.

  • 'Source' is from 'package:audioplayers/src/source.dart' ('../../AppData/Local/Pub/Cache/hosted/pub.dev/audioplayers-4.1.0/lib/src/source.dart').
    int result = await audioPlayer.play(url);
    ^
    lib/main.dart:106:20: Error: This expression has type 'void' and can't be used.
    int result = await audioPlayer.play(url);
    ^
    please help me resolve this error

from clima-flutter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.