Expected a value of type 'int', but got one of type 'String' json flutter, после hot reload в браузере работает
Пытаюсь вывести в Text декодированный ответ сервера, пробовал запустить и в браузере и на устройстве, на устройстве просто выдает экран ошибки, а в браузере после экрана ошибки всё прогружается и работает как надо.Листинг программы ниже:
import 'package:http/http.dart' as http;
import 'package:flutter/material.dart';
import 'dart:convert';
String firs_name="";
List<dynamic> dataList = <String>[""];
class Message extends StatefulWidget {
@override
createState() => new MyWidgetState();
}
class MyWidgetState extends State<Message> {
@override
Widget build(BuildContext context) {
return new ListView(children: [Container(color: Colors.white60, height: 40,width: 100,
child:Row(children: [Column(children: [Text(""),Text("Номер телефона")],),Container(
margin: EdgeInsets.only(left: 10),
child:
IconButton(onPressed: (){},icon: const Icon(Icons.check) ,color: Colors.green,),
),
Container(
margin: EdgeInsets.only(left: 10),
child:
IconButton(onPressed: (){},icon: const Icon(Icons.close) ,color: Colors.red,),
)],
)
)
],);
}
}
void main() => runApp(MyApp());
int count = 0;
final List<int> items = <int>[1,2,3,4,5,6];
class MyApp extends StatefulWidget {
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Widget build(BuildContext context) {
void Connect() async {
var headers = {
'Content-Type': 'application/json',
};
var data = '{""}';
var url = Uri.parse('******');
var res = await http.post(url, headers: headers, body: data);
if (res.statusCode != 200) throw Exception('http.post error: statusCode=
${res.statusCode}');
print(res.body);
dataList=jsonDecode(res.body) as List<dynamic>;
print(dataList);
}
Connect();
return MaterialApp(
home:
Scaffold(
appBar: AppBar(backgroundColor: Colors.orange, title: Text("Подтверждение регистрации",style: TextStyle(fontSize: 15),),
leading: Builder(
builder: (BuildContext context) {
return IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () {},
);
},
),
),
body:ListView.builder(
padding: const EdgeInsets.all(10),
itemCount: dataList.length,
itemBuilder: (BuildContext context, int index)
{
return Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.white38,
),
borderRadius: BorderRadius.all(Radius.circular(20))
),
child: Row(children: [Column(children:
[Text(dataList[index]['email']),
// Text(dataList[index]["last_name"]!.toString()),
//Text(dataList[index]["Patronymic"]!.toString()),
// Text(dataList[index]["email"]!.toString()),
],),Container(
margin: EdgeInsets.only(left: 20),
child:
IconButton(onPressed: (){void Accept_true() async {
var headers = {
'Content-Type': 'application/json',
};
var data = '{"email":"${dataList[index]['email']}","accept":"true"}';
print(dataList[index]["email"]);
var url = Uri.parse('***');
var res = await http.post(url, headers: headers, body: data);
if (res.statusCode != 200) throw Exception('http.post error: statusCode= ${res.statusCode}');
}
Accept_true();},icon: const Icon(Icons.check) ,color: Colors.green,),
),
Container(
margin: EdgeInsets.only(left: 20),
child:
IconButton(onPressed: (){void Accept_false() async {
var headers = {
'Content-Type': 'application/json',
};
var data = '{"email":"${dataList[index]['email']}","accept":"false"}';
print(dataList[index]["email"]);
var url = Uri.parse('***');
var res = await http.post(url, headers: headers, body: data);
if (res.statusCode != 200) throw Exception('http.post error: statusCode= ${res.statusCode}');
}
Accept_false();
},icon: const Icon(Icons.close) ,color: Colors.red,),
)],)
);
}
)
,),
);
} }