title: Unhandled Exception: FormatException: Unexpected end of input (at character 1) in flutter (in shared_preferences)
body: <p>I'm making a task book, on a flutter, in this project I will use a lot of packages that I have not worked with before (this is not my first question on this project). My goal is to create tasks to add to the status (finished, not finished), and save them locally on the device. I wrote code (with some packages to help me figure it out) that does it all. But the problem arose when downloading questions from the local repository when starting the application. I have an error not to decode the data (in the repository I save a list of our tasks and status). Maybe someone faced such a problem I will be grateful for your help)</p>
  <pre><code>import 'dart:async';
  import 'dart:convert';
  import 'package:flutter/material.dart';
  import 'package:shared_preferences/shared_preferences.dart';
  import 'package:testjob/jsonTodo.dart';
  void main() {
    runApp(MaterialApp(
      home: App(),
    ));
  }
  
  
  
  class _strikeThrough extends StatelessWidget {
    final String todoText;
    final bool todoCheck;
    _strikeThrough(this.todoText, this.todoCheck) : super();
  
    Widget _widget() {
      if (todoCheck) {
        return Text(
          todoText,
          style: TextStyle(
            fontSize: 22.0,
          ),
        );
      } else {
        return Text(
          todoText,
          style: TextStyle(fontSize: 22.0),
        );
      }
    }
  
    @override
    Widget build(BuildContext context) {
      return _widget();
    }
  }
  
  class App extends StatefulWidget {
    @override
    AppState createState() {
      return AppState();
    }
  }
  
  final ValueNotifier&lt;ThemeMode&gt; _notifier = ValueNotifier(ThemeMode.light);
  
  class AppState extends State&lt;App&gt; {
  
  
  
    bool valText = true;
    var IconsType = Icons.wb_sunny;
  
    late Color ColorType = Colors.black;
  
    var textController = TextEditingController();
    var popUpTextController = TextEditingController();
  
    List&lt;TodoInfo&gt; WidgetList = [];
  
    @override
    void dispose() {
      textController.dispose();
      popUpTextController.dispose();
      super.dispose();
    }
  
    @override
    void initState() {
      getSP();
      super.initState();
    }
  
    Future&lt;void&gt; addToSP(List&lt;List&lt;TodoInfo&gt;&gt; tList) async {
      final prefs = await SharedPreferences.getInstance();
      prefs.setString('todoLists', jsonEncode(tList));
    }
  
    void getSP() async {
      final prefs = await SharedPreferences.getInstance();
      final List&lt;dynamic&gt; jsonData =
      jsonDecode(prefs.getString('todoLists') ?? '');
      if (jsonData.isNotEmpty) {
        for (var data in jsonData) {
          final d = TodoInfo.fromJson(data);
          WidgetList.add(d);
        }
        setState(() {});
      }
    }
  
  
  
    @override
    Widget build(BuildContext context) {
      return ValueListenableBuilder&lt;ThemeMode&gt;(
          valueListenable: _notifier,
          builder: (_, mode, __) {
            return MaterialApp(
                theme: ThemeData.light(),
                darkTheme: ThemeData.dark(),
                themeMode: mode, // Decides which theme to show, light or dark.
                home: Scaffold(
                  appBar: AppBar(
                    title: Text(&quot;Список задач&quot;),
                    actions: &lt;Widget&gt;[
                      IconButton(
                          icon: Icon(IconsType, color: ColorType),
                          onPressed: () =&gt; {
                            if (_notifier.value == ThemeMode.light)
                              {
                                _notifier.value = ThemeMode.dark,
                                IconsType = Icons.dark_mode,
                                ColorType = Colors.white,
                              }
                            else
                              {
                                _notifier.value = ThemeMode.light,
                                IconsType = Icons.wb_sunny,
                                ColorType = Colors.black,
                              }
                          })
                    ],
  //backgroundColor: Colors.orange[500],
                    iconTheme: IconThemeData(color: Colors.white),
                  ),
                  body: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: &lt;Widget&gt;[
                      Container(
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: &lt;Widget&gt;[
                            const Text(
                              &quot;Tasks&quot;,
                              style: TextStyle(
                                fontSize: 70.0,
                                fontWeight: FontWeight.bold,
                                color: Colors.black,
                              ),
                            ),
                            IconButton(
                              color: Colors.black,
                              iconSize: 70,
                              constraints: const BoxConstraints(),
                              padding: EdgeInsets.fromLTRB(30.0, 10.0, 30, 10.0),
                              icon: const Icon(Icons.add_outlined),
                              onPressed: () {
                                if (textController.text
                                    .replaceAll(&quot; &quot;, &quot;&quot;)
                                    .isNotEmpty) {
                                  WidgetList.insert(0,  TodoInfo(todoText:textController.text.replaceAll(&quot; &quot;, &quot;&quot;), todoCheck: false ));
                                  addToSP;
                                  setState(() {
                                    valText = true;
                                    textController.clear();
                                  });
                                } else {
                                  setState(() {
                                    valText = false;
                                  });
                                }
                              },
                            )
                          ],
                        ),
                      ),
                      Container(
                        width: MediaQuery.of(context).size.height * 0.45,
                        child: TextField(
                          style: TextStyle(
                            fontSize: 22.0,
  //color: Theme.of(context).accentColor,
                          ),
                          controller: textController,
                          cursorWidth: 5.0,
                          autocorrect: true,
                          autofocus: true,
  //onSubmitted: ,
                        ),
                      ),
                      Align(
                          child: (valText == false)
                              ? Align(
                              child: Text((&quot;Задача пустая&quot;),
                                  style: TextStyle(
                                      fontSize: 25.0, color: Colors.red)),
                              alignment: Alignment.center)
                              : Align(
                              child: Text(
                                (&quot;&quot;),
                              ),
                              alignment: Alignment.center)),
                      Expanded(
                        child: ReorderableListView(
                          children: &lt;Widget&gt;[
                            for (final widget in WidgetList)
                              GestureDetector(
                                key: Key(widget.todoText),
                                child: Dismissible(
                                  key: Key(widget.todoText),
                                  child: CheckboxListTile(
                                    controlAffinity:
                                    ListTileControlAffinity.leading,
  //key: ValueKey(&quot;Checkboxtile $widget&quot;),
                                    value: widget.todoCheck,
                                    title: _strikeThrough(
                                        widget.todoText, widget.todoCheck),
                                    onChanged: (checkValue) {
  //_strikethrough toggle
                                      setState(() {
                                        if (!checkValue!) {
                                          widget.todoCheck = false;
                                        } else {
                                          widget.todoCheck = true;
                                        }
                                      });
                                    },
                                  ),
                                  background: Container(
                                    child: Icon(Icons.delete),
                                    alignment: Alignment.centerRight,
                                    color: Colors.redAccent,
                                  ),
                                  direction: DismissDirection.endToStart,
                                  movementDuration:
                                  const Duration(milliseconds: 200),
                                  onDismissed: (dismissDirection) {
  //Delete Todo
                                    WidgetList.remove(widget);
                                  },
                                ),
                              )
                          ],
                          onReorder: (oldIndex, newIndex) {
                            setState(() {
                              if (newIndex &gt; oldIndex) {
                                newIndex -= 1;
                              }
                              var replaceWiget = WidgetList.removeAt(oldIndex);
                              WidgetList.insert(newIndex, replaceWiget);
                            });
                          },
                        ),
                      )
                    ],
                  ),
                ));
          });
    }
  }
  
  class TodoInfo {
    String todoText;
    bool todoCheck;
  
    TodoInfo({
      required this.todoText,
      required this.todoCheck,
    });
  
    factory TodoInfo.fromJson(Map&lt;String, dynamic&gt; json) {
      return TodoInfo(todoText: json[&quot;todoText&quot;], todoCheck: json[&quot;todoCheck&quot;]);
    }
  
    factory TodoInfo.fromMap(Map&lt;String, dynamic&gt; map) =&gt;
        TodoInfo(
          todoText: map[&quot;todoText&quot;] ?? '',
          todoCheck: map[&quot;todoCheck&quot;] ?? '',
        );
  
    Map&lt;String, dynamic&gt; toJson() {
      return {&quot;todoText&quot;: todoText, &quot;todoCheck&quot;: todoCheck};
    }
  
    @override
    String toString() =&gt; '{todoText: $todoText, todoCheck: $todoCheck}';
  }
  </code></pre>
  <p>My erorr</p>
  <pre><code>E/flutter (30831): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: FormatException: Unexpected end of input (at character 1)
  E/flutter (30831): 
  E/flutter (30831): ^
  E/flutter (30831): 
  E/flutter (30831): #0      _ChunkedJsonParser.fail (dart:convert-patch/convert_patch.dart:1404:5)
  E/flutter (30831): #1      _ChunkedJsonParser.close (dart:convert-patch/convert_patch.dart:522:7)
  E/flutter (30831): #2      _parseJson (dart:convert-patch/convert_patch.dart:41:10)
  E/flutter (30831): #3      JsonDecoder.convert (dart:convert/json.dart:506:36)
  E/flutter (30831): #4      JsonCodec.decode (dart:convert/json.dart:157:41)
  E/flutter (30831): #5      jsonDecode (dart:convert/json.dart:96:10)
  E/flutter (30831): #6      AppState.getSP (package:testjob/main.dart:85:5)
  E/flutter (30831): &lt;asynchronous suspension&gt;
  E/flutter (30831): 
  </code></pre>