Reputation: 152
I am trying to insert a string into my list of strings.
I initialize my string like so in a class called globals that holds this list.
List<String> myStringList = [];
Then in my controller class I am trying to insert a string into the list like so.
globals.myStringList.add(stringToAdd);
But I get an error that says the list is null. Not sure if I am initializing it wrong since it appears this is the way to initialize an empty list.
Globals Class
import 'package:flutter_project/models/categories.dart';
import 'package:flutter_project/models/videos.dart';
List<String> reports = [];
List<Video> videos = [];
List<Category> categories = [];
List<String> userSearches = <String>[];
bool inSearch = false;
Upvotes: 0
Views: 1419
Reputation: 1969
Make the variable static so that it can be accessible by the class name
Upvotes: -1
Reputation: 152
Found the answer, I was initializing my string incorrectly. It has to be done like so.
List<String> myStringList = <String>[];
Upvotes: 3