Not able to send GET/POST requests after connecting to wifi through my flutter app

I’m creating a flutter app to connect to a IOT speaker device (which has wifi). I need to connect to it and upload audio files using GET/POST APIs. If I connect my phone to speaker’s wifi using the wifi option already present in the android phone, I am able to upload the file through the POST request. If i connect to the speaker wifi through the Flutter app using wiflutter package, I’m not able to do the POST request.

package:wiflutter/wiflutter.dart’; — It connects to wifi, but it doesnt allow me to do GET/POST requests.

I have tried many other packages as well. They have not been updated for long time.

Below are the packages that i tried:

‘package:wifi_scan/wifi_scan.dart’; — only scans for wifi

package:wifi/wifi.dart’; — it seems to be outdated package

‘package:wifi_connector/wifi_connector.dart’; — I’m getting an error that the package uses outdated Kotlin plugin version. Cant seem to workaround this.

I’m relatively new to flutter. Any help would be appreciated!

Code for connecting to wifi:

    import 'package:flutter/material.dart';

import 'package:flutter/widgets.dart';

import 'package:nspeak/RecordingPage.dart';

import 'package:wifi_scan/wifi_scan.dart';

import 'package:wiflutter/wiflutter.dart';

import 'package:wiflutter/enums/enterprise_certificate_enum.dart';

// import 'package:wifi_iot/wifi_iot.dart'; -- doesnt support Null safety, so cant use it.

// import 'package:wifi_connector/wifi_connector.dart'; --it uses older Kotlin plugin version. So cant use it.

// import 'package:wifi_configuration/wifi_configuration.dart'; -- doesnt support Null safety, so cant use it.

// import 'package:wifi/wifi.dart'; -- doesnt support Null safety, so cant use it.

scanNspeakwifi() async{

resultcanstarscan = await WiFiScan.instance.canStartScan();

// print("passed canstartscan : $resultcanstarscan");

if(resultcanstarscan == CanStartScan.yes){

scansuccess = await WiFiScan.instance.startScan();

// print("scan success: $scansuccess");

if (mounted){

ScaffoldMessenger.of(context).showSnackBar(

const SnackBar(

padding: EdgeInsets.only(bottom: 25,),

duration: Durations.extralong4,

backgroundColor: Colors.yellow,

content: Center(child:Text('Scanning in progress', style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold, color: Colors.black),),

)),

);

}

}

else {

if(mounted){

ScaffoldMessenger.of(context).showSnackBar(

const SnackBar(

padding: EdgeInsets.only(bottom: 25,left: 30, right: 30),

duration: Durations.extralong4,

backgroundColor: Colors.red,

content: Center( child: Text('Cannot start scan. Check if all necessary permissions are given!', style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),),

),

)

);

}

}

cangetresults = await WiFiScan.instance.canGetScannedResults();

// print("Passed cangetresults $cangetresults");

if(cangetresults == CanGetScannedResults.yes ){

scanresults = await WiFiScan.instance.getScannedResults();

if(mounted){

ScaffoldMessenger.of(context).showSnackBar(

const SnackBar(

padding: EdgeInsets.only(bottom: 25, left: 20, right: 20),

duration: Durations.extralong4,

backgroundColor: Colors.green,

content: Center(child: Text('Scan completed! Click on "Get Results" to view nearby Nspeak device', style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),)),

),

);

}

}

else {

if(mounted){

ScaffoldMessenger.of(context).showSnackBar(

const SnackBar(

padding: EdgeInsets.only(bottom: 25,left: 20, right: 20),

duration: Durations.extralong4,

backgroundColor: Colors.red,

content: Center(child: Text('No scan result available. Check if all necessary permissions are given!', style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),)),

),

);

}

}

}

getNspeakwifi() async {

var resultsavail = await WiFiScan.instance.onScannedResultsAvailable;

var checkresult = await resultsavail.isEmpty;

if (!checkresult){

setState(() {

wifiNetworks = scanresults;

_shownetworks = true;

});

}

else{

if(mounted){

ScaffoldMessenger.of(context).showSnackBar(

const SnackBar(

padding: EdgeInsets.only(bottom: 25, left: 20, right: 20),

duration: Durations.extralong4,

backgroundColor: Colors.red,

content: Center(child: Text('No Nspeak devices nearby! ', style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),)),

),

);

}

}

}

Widget displayNspeak(){

var value;

nspeakdevices = []; /*Initialzied the variable here again because everytime "Get results" is clicked, it should return a new list. It should not go on adding the Wifi ACcess points to the same list*/

for (int i=0; i<wifiNetworks.length;){

var entry = wifiNetworks[i];

if(entry.ssid.contains("NSPEAK")){

value = entry.ssid;

print("reached List");

nspeakdevices.add(value);

}

i++;

}

if (nspeakdevices.isNotEmpty){

return ListView.builder(itemCount: nspeakdevices.length,

itemBuilder: (BuildContext context, int index){

var nspeakvalue = nspeakdevices[index];

return Row(

children: [

Expanded(child: ListTile(title: Text(nspeakvalue))),

TextButton(onPressed: () async {

var con = await wiflutter.connect(

ssid: nspeakvalue,

password: '********',

);

},

child: Text("Connect", style: TextStyle(fontSize: 10),)

),

TextButton(onPressed: () async {

var con = await wiflutter.disconnect();

},

child: Text("Disconnect", style: TextStyle(fontSize: 10),)),

],

);

}

);

}

else {

return const Text("No Nspeak devices nearby");

}

}

}

Code for uploading the audio file:

    fileupload() async{

try {

var headersget = {'Authorization': 'Authorization text'};

requestget = http.Request('GET', Uri.parse('http://192.168.4.1/getlogin'));

requestget.headers.addAll(headersget);

http.StreamedResponse responseget = await requestget.send();

// print(responseget.statusCode);

if (responseget.statusCode == 200){

ScaffoldMessenger.of(context).showSnackBar(

const SnackBar(

padding: EdgeInsets.only(bottom: 50, left: 50),

duration: Durations.extralong4,

backgroundColor: Colors.white,

content: Text('Login Successfull!', style: TextStyle(fontSize: 15, color: Colors.black , fontWeight: FontWeight.bold),),

),);

}

else{

ScaffoldMessenger.of(context).showSnackBar(

const SnackBar(

padding: EdgeInsets.only(bottom: 50, left: 50),

duration: Durations.extralong4,

// backgroundColor: Colors.white,

content: Text('Login failed', style: TextStyle(fontSize: 15, color: Colors.black, fontWeight: FontWeight.bold),),

),);

}

var headerspost = {Content-Type': 'multipart/form-data;',

'Authorization': 'authorization text'};

requestpost = http.MultipartRequest('POST', Uri.parse('http://192.168.4.1/upload'));

// print("parse successfull");

requestpost.files.add(await http.MultipartFile.fromPath('mp3', audiofilepath));

print("file add successfull");

requestpost.headers.addAll(headerspost);

print("headers add successfull");

http.StreamedResponse responsepost = await requestpost.send();

print("POST request sent");

// print(requestpost.body);

// print(responsepost.statusCode);

// print(responsepost.headers["Location"]);

if (responsepost.statusCode == 200 || responsepost.statusCode == 302){

ScaffoldMessenger.of(context).showSnackBar(

const SnackBar(

padding: EdgeInsets.only(bottom: 50, left: 50),

duration: Durations.extralong4,

backgroundColor: Colors.white,

content: Text('File has been uploaded!', style: TextStyle(fontSize: 15, color: Colors.black , fontWeight: FontWeight.bold),),

),);

}

else{

ScaffoldMessenger.of(context).showSnackBar(

const SnackBar(

padding: EdgeInsets.only(bottom: 50, left: 50),

duration: Durations.extralong4,

// backgroundColor: Colors.white,

content: Text('File upload failed', style: TextStyle(fontSize: 15, color: Colors.black, fontWeight: FontWeight.bold),),

),);

}

}

catch (e){

print('Error uploading audio: $e');

}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật