Skip to content

why i am getting null error #101

@nischal690

Description

@nischal690

ist<Map<String, dynamic>> data1 = [];

class Mentions extends StatefulWidget {
const Mentions({
Key? key,
this.width,
this.height,
}) : super(key: key);

final double? width;
final double? height;

@OverRide
_MentionsState createState() => _MentionsState();
}

class _MentionsState extends State {
GlobalKey key = GlobalKey();
Future apicall() async {
http.Response response;
var url = "https://7J8Y54OD18-dsn.algolia.net/1/indexes/users";
response = await http.get(Uri.parse(url), headers: {
'X-Algolia-API-Key': '841e31106f80e21b89b0d2b9ec7cd561',
'X-Algolia-Application-Id': '7J8Y54OD18'
});
if (response.statusCode == 200) {
setState(() {
jsonMap = json.decode(response.body);
(jsonMap['hits'] as List).forEach((x) => {data.add(Map.from(x))});
for (int i = 0; i < data.length; i++) {
data1
.add({'id': data[i]["objectID"], 'display': data[i]["username"]});
}
});
} else {
string = "fsfwe";
}
}

void generatedata() {}

@OverRide
void initState() {
apicall();

super.initState();

}

@OverRide
Widget build(BuildContext context) {
return Portal(
child: Scaffold(
appBar: AppBar(
title: Text("flutter mention"),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(data1.length.toString()),
Container(
child: FlutterMentions(
key: key,
suggestionPosition: SuggestionPosition.Top,
maxLines: 5,
minLines: 3,
decoration: InputDecoration(hintText: 'hello'),
mentions: [
Mention(
trigger: '@',
style: TextStyle(
color: Colors.amber,
),
data: data1,
matchAll: false,
suggestionBuilder: (data1) {
return Container(
padding: EdgeInsets.all(10.0),
child: Row(
children: [
SizedBox(
width: 20.0,
),

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions