Comments (18)
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.
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.
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.
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.
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.
Im having issues with same problem...
from clima-flutter.
In NetworkHelper as you are returning something it cant be void
from clima-flutter.
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.
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.
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.
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.
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.
Im having issues with same problem...
me too
from clima-flutter.
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.
i have also same problem.
from clima-flutter.
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.
from clima-flutter.
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)
- Error: NoSuchMethodError: The getter 'latitude' was called on null. HOT 1
- Failed to navigate to location_screen.dart on app restart HOT 1
- Type "double" is not a subtype of type "int"
- When I write the city name and pressing on "Get Weather" it throws me this error in the console HOT 5
- Migrating Project HOT 3
- the code seems to stop at await .
- This expression has a type of 'void' so its value can't be used. Try checking to see if you're using the correct API; there might be a function or call that returns void you didn't expect. Also check type parameters and variables which might also be void.
- Unable to run the app after adding package Geolocator HOT 1
- NoSuchMethodError HOT 1
- Unable to print decodeData(); into the console HOT 3
- 'position' isn't printed HOT 1
- Error on Gathering API data using variables HOT 1
- permission HOT 3
- Permission denied error HOT 6
- everyone who are facing location denied problem and did not find position here is the solution welcome in advance :) HOT 1
- Problem when i click on get weather HOT 2
- Having a red flag from the beginning'' RaisedButton on Location Screen isn't defined as well as the FlatButton '' HOT 1
- Unable to pass url to my class object (NetworkHelper ) in loading screen HOT 1
- I have issue in getlocationData() method using Navigator.push of LocationScreen();
- issue in uploading my clima app project on github
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clima-flutter.