Estava tentando fazer uma ligação flutter com firebase realtime e agora esta aparecendo isso
I/flutter (18636): FormatException: Unexpected character (at line 2, character 1)
I/flutter (18636): <!DOCTYPE html>
I/flutter (18636): ^
Meus arquivos principais: UserApi
import 'dart:convert' as convert;
import 'package:fluter_crud/models/user.dart';
import 'package:http/http.dart' as http;
class UserApi {
static Future<List<User>> getUser() async {
final String url = 'https://app-armario.firebaseio.com/';
var response = await http.get(url);
String json = response.body;
List list = convert.json.decode(json);
final user = List<User>();
for (Map map in list) {
User c = User.fromJson(map);
user.add(c);
}
print(user);
return user;
}
}
Classe do User
import 'package:flutter/material.dart';
class User {
String id;
String name;
String email;
String avatarUrl;
User({
this.id,
@required this.name,
@required this.email,
@required this.avatarUrl,
});
User.fromJson(Map<String, dynamic> json) {
id = json['id'];
name = json['name'];
avatarUrl = json['avatarUrl'];
email = json['email'];
}
Map<String, User> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['name'] = this.name;
data['email'] = this.email;
data['avatarUrl'] = this.avatarUrl;
return data;
}
}
Parte de criar a lista:
import 'package:fluter_crud/components/user_tile.dart';
import 'package:fluter_crud/models/user.dart';
import 'package:fluter_crud/provider/users.dart';
import 'package:fluter_crud/routes/app_routes.dart';
import 'package:fluter_crud/utils/User_api.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class UserList extends StatelessWidget {
//Future<void> _refreshUsers(BuildContext context) {}
@override
Widget build(BuildContext context) {
//final Users usersData = Provider.of(context);
return Scaffold(
appBar: AppBar(
title: Text('Lista de Usuários'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.add),
onPressed: () {
Navigator.of(context).pushNamed(
AppRoutes.USER_FORM,
);
},
)
],
),
body: teste(),
);
}
teste() {
Future<List<User>> future = UserApi.getUser();
return FutureBuilder(
future: future,
builder: (context, snapshot) {
if (!snapshot.hasError) {
print(snapshot.error);
return Center(child: Text("Erro ao carregar banco de dados"));
}
if (!snapshot.hasData) {
print(snapshot.error);
print(snapshot.data);
return Center(
child: CircularProgressIndicator(),
);
}
List<User> users = snapshot.data;
return _listView(users);
},
);
}
Container _listView(List<User> users) {
return Container(
child: ListView.builder(
itemCount: users != null ? users.length : 0,
itemBuilder: (ctx, i) {
User u = users[i];
return UserTile(u);
},
),
);
}
}
//RefreshIndicator( onRefresh: () => _refreshUsers(context),child:
//itemBuilder: (ctx, i) => UserTile(usersData.byIndex(i),