Instance of 'Future<String>' instead of showing the value

There is await missing before prefs.getString( and use setState() instead of returning the value. build() can't use await.

  String _patientPhone;

  Future<void> getPhone() async {
    final SharedPreferences prefs = await SharedPreferences.getInstance();
    final String patientPhone = await /*added */ prefs.getString('patientPhone');
    print(patientPhone);

    setState(() => _patientPhone = patientPhone);
  }

  build() {
    ...
    Center(child: _patientPhone != null ? Text('${_patientPhone}') : Container(),))
  }

Tags:

Dart

Flutter