I want to know how I can make it so that when it shows me the data stored in my database, it does not show true or false but, for example, yes or no
This is the page where I show my data stored in the database to the application
class _readDataState extends State<readData> {
final Stream<QuerySnapshot> users = FirebaseFirestore.instance
.collection('users')
.orderBy('Fecha ingreso sintoma')
.snapshots();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Sintomas'),
backgroundColor: Color.fromARGB(255, 230, 57, 137),
elevation: 0.0,
),
body: SingleChildScrollView(
child: Column(
children: [
Container(
height: 730,
padding: const EdgeInsets.symmetric(vertical: 5),
child: StreamBuilder<QuerySnapshot>(
stream: users,
builder: (
BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshot,
) {
if (snapshot.hasError) {
return Text('Algo salio mal');
}
if (snapshot.connectionState == ConnectionState.waiting) {
return Text('Cargando');
}
final data = snapshot.requireData;
return ListView.builder(
itemCount: data.size,
itemBuilder: (context, index) {
return Card(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text('Síntomas'),
Text( // Here I show the data in the application
'${data.docs[index]['Fecha ingreso sintoma']}'),
Text('''
Fatiga: ${data.docs[index]['Fatiga']}
Miccion: ${data.docs[index]['Miccion']}
Flujo Vaginal: ${data.docs[index]['Flujo Vaginal']}
Estreñimiento: ${data.docs[index]['Estreñimiento']}
Acidez Gastrica: ${data.docs[index]['Acidez Gastrica']}
Sangrado Nasal: ${data.docs[index]['Sangrado Nasal']}
Sangrado de encias: ${data.docs[index]['Sangrado de encias']}
Hinchazon: ${data.docs[index]['Hinchazon']}
Problemas respiratarios: ${data.docs[index]['Problemas respiratarios']}
''')
This is how it shows me in the app
I would like that instead of showing true or false, it would show me yes or no or some other text or only show me true.
CodePudding user response:
You use ternary expression like
Text("${isTrue? "Yex" : "No"}"),
For your case it will be like
Text('''
Fatiga: ${data.docs[index]['Fatiga'] ? "Yes" : "No"}
......
Repeat the process for others.
Also you can create sample method for this like
String boolToYesNO(bool? data) {
return data == true ? "Yes" : "No";
}
And use like
Fatiga: ${boolToYesNO(data.docs[index]['Fatiga'])}