I have created a ListTile to return all my documents from my collection in Firestore. But I want to put "R$" before the number, not above it:
Is there a way to do it? Also, I would like to know if there is how to put more information before the ListTile. When I try to create a Text, it gives me an error:
This is the code:
class FinancasMensais extends StatefulWidget {
const FinancasMensais({super.key});
@override
State<FinancasMensais> createState() => _FinancasMensaisState();
}
class _FinancasMensaisState extends State<FinancasMensais> {
final _fireStore = FirebaseFirestore.instance;
final ref =
FirebaseFirestore.instance.collection('addsaidas').snapshots();
Future<void> getData() async {
QuerySnapshot querySnapshot =
await _fireStore.collection('addsaidas').get();
final allData = querySnapshot.docs.map((doc) => doc.data()).toList();
for (var dataMap in allData) {
if (dataMap is Map) {
for (var key in dataMap.keys) {
print('$key: ${dataMap[key]}');
}
print('----------------------');
}
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Color.fromARGB(255, 92, 172, 178),
centerTitle: true,
title: Text('Finanças Mensais'),
toolbarHeight: 90,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40)
),
elevation: 15,
),
body: StreamBuilder<QuerySnapshot>(
//child: Center(child: Text('Todo Task'),),
stream: ref,
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const Center(child: CircularProgressIndicator());
}
final documents = snapshot.data!.docs;
return ListView.builder(
itemCount: documents.length,
itemBuilder: (context, index) {
final document = documents[index];
final data = document.data() as Map<String, dynamic>;
return ListTile(
contentPadding: EdgeInsets.only(left: 15, right: 15, top: 15, bottom: 4),
leading: Icon(Icons.where_to_vote_outlined,
color: Colors.pink,
size: 36,
),
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(data['nomesaida'],
style: TextStyle(
fontSize: 22,
),),
Text(data['tipocategoria']),
],
),
trailing: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text("R$",
style: TextStyle(
fontSize: 15
),
),
Text(data['valorsaida'] as String,
style: TextStyle(
color: Colors.pink,
fontSize: 28,
),),
Text(data['datasaida'],
style: TextStyle(
color: Colors.pink
),),
],
),
dense: false,
);
},
);
},
),
);
}
}
2
Answers
Duda!
The
R$
is above the number cause you’re putting all of them inside a Column – that aligns the children always vertically.To make the
R$
appears at the left of the number, you can wrap both inside a Row.But you can also use the
intl
library to format currency for you. Give a try to that.Let me outline what you want to do with the above code:
Let’s talk about where you may be wrong with your approach.
Assuming you have styling constraints to adhere to, try using RichText Widget.
Hope this helps you.