简体   繁体   English

记事本 - RangeError(索引):无效值:有效值范围为空:0 - flutter

[英]Notepad - RangeError (index): Invalid value: Valid value range is empty: 0 - flutter

I want to save text and date to txt file and load it but I am getting "RangeError (index): Invalid value: Valid value range is empty: 0"我想将文本和日期保存到 txt 文件并加载它,但我收到“RangeError (index): Invalid value: Valid value range is empty: 0”

void _loadNotes() async {
    var directory = await getApplicationDocumentsDirectory();
    var file = File("${directory.path}/notable.txt");
    if (!await file.exists()) {
      file.createSync();
      file.writeAsStringSync("Hello, World!#This is your first note.\n");
    }
    var contents = await file.readAsString();
    var contentsList = contents.split("\n");
    for (var i = 0; i < contentsList.length; i++) {
      var noteLine = contentsList[i].split("#");
      _notes.add(noteLine[0]);
      _noteAddedDates.add(noteLine[1]);
    }
  }
  void _saveNotes() async {
    var directory = await getApplicationDocumentsDirectory();
    var file = File("${directory.path}/notable.txt");
    var contents = "";
    for (var i = 0; i < _notes.length; i++) {
      contents += _notes[i] + "#" + _noteAddedDates[i] + "\n";
    }
    await file.writeAsString(contents);
  }
    void _loadNotes() async {
        var directory = await getApplicationDocumentsDirectory();
        var file = File("${directory.path}/notable.txt");
        if (!await file.exists()) {
          file.createSync();
          file.writeAsStringSync("Hello, World!#This is your first note.\n");
        }
        var contents = await file.readAsString();
        var contentsList = contents.split("\n");
    Future.delayed(Duration(milliseconds: 1000), () {

//add this delay 
          for (var i = 0; i < contentsList.length; i++) {
          var noteLine = contentsList[i].split("#");
          _notes.add(noteLine[0]);
          _noteAddedDates.add(noteLine[1]);
        }                                            
            });
     
      }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 flutter:RangeError(索引):无效值:有效值范围为空: - flutter : RangeError (index): Invalid value: Valid value range is empty: RangeError(索引):无效值:有效值范围为空:0,Flutter - RangeError (index): Invalid value: Valid value range is empty: 0, Flutter "RangeError (index): Invalid value: Valid value range is empty: 2" with flutter carousel - "RangeError (index): Invalid value: Valid value range is empty: 2" with flutter carousel RangeError(索引):无效值:有效值范围为空:0 - Flutter - RangeError (index): Invalid value: Valid value range is empty: 0 - Flutter Flutter:RangeError(索引):无效值:有效值范围为空:-1 - Flutter: RangeError (index): Invalid value: Valid value range is empty: -1 flutter error : RangeError (index): Invalid value: 有效值范围为空:0 - flutter error : RangeError (index): Invalid value: Valid value range is empty: 0 RangeError(索引):无效值:有效值范围为空:0 | Flutter Firebase - RangeError (index): Invalid value: Valid value range is empty: 0 | Flutter Firebase RangeError(索引):无效值:有效值范围为空:0 错误 Flutter - RangeError (index): Invalid value: Valid value range is empty: 0 Error Flutter Flutter:RangeError(索引):无效值:有效值范围为空:0 - Flutter: RangeError (index): Invalid value: Valid value range is empty: 0 Flutter &quot;RangeError (index): Invalid value: Valid value range is empty: 0 with WidgetSpan - Flutter "RangeError (index): Invalid value: Valid value range is empty: 0 with WidgetSpan
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM