How I got data from the txt file.
Future<String>? get textAsString async {
Uri? uri = Uri.tryParse(text.url);
if (uri != null) {
String text = await http.read(uri);
return text;
}
return '';
}
My widget structure and code layout.
FutureBuilder<String>(
future: currentScene.textAsString,
builder: (context, snapshot) {
String? text = snapshot.data;
if (snapshot.hasData && text != null) {
return ListView(
padding: kAppPadding,
controller: _controller,
children: [
Text(
text,
style: TextStyle(
height: 1.8,
fontFamily: 'Roboto',
color: kWhiteColor,
fontWeight: FontWeight.w300,
fontSize: 17,
),
),
],
);
} else if (snapshot.hasError) {
return Center(
child: AppErrorText(
onPressed: () {},
),
);
} else {
return Center(
child: AppProgressIndicator(),
);
}
})
I have a TXT url stored in cloud storage and I want to retrieve the text and create a text reader app.
I used http.read(uri) to get the content of the TXT file and passed the String to a Text Widget wrapped with a FutureBuilder
I noticed the String contained some weird characters (â)... so I looking for a way to remove/replace those characters.