Home > database >  Adding ElevatedButton under or inside StreamBuilder
Adding ElevatedButton under or inside StreamBuilder

Time:05-31

I want to add a button on the bottom of my page but i dont know how to add ElevatedButton inside or under StreamBuilder

I would also want to add a class in this page after the StreamBuilder

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';

class OrderSuccessful extends StatefulWidget {
  @override
  _OrderSuccessfulState createState() => _OrderSuccessfulState();
}

class _OrderSuccessfulState extends State<OrderSuccessful>{
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Order Successful")),
      resizeToAvoidBottomInset: true,
      body: StreamBuilder(
        stream: FirebaseFirestore.instance.collection('personalinfo').snapshots(),
        builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot){
          if (!snapshot.hasData){
            return Text("no value");
          }
          return ListView(
            children: snapshot.data!.docs.map((document){
              return Text(document['field1']   " "   document['field2']   " "   document['field3']   " "   document['field4'], textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold, fontSize: 18));
            }).toList(),
          );
        },
      ),
    );
  }
}

CodePudding user response:

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';

class OrderSuccessful extends StatefulWidget {
  @override
  _OrderSuccessfulState createState() => _OrderSuccessfulState();
}

class _OrderSuccessfulState extends State<OrderSuccessful> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: Text("Order Successful")),
        resizeToAvoidBottomInset: true,
        body: Column(
          children: [
            StreamBuilder(
              stream: FirebaseFirestore.instance
                  .collection('personalinfo')
                  .snapshots(),
              builder: (BuildContext context,
                  AsyncSnapshot<QuerySnapshot> snapshot) {
                if (!snapshot.hasData) {
                  return Text("no value");
                }
                return ListView(
                  shrinkWrap:true,
                  children: snapshot.data!.docs.map((document) {
                    return Text(
                        document['field1']  
                            " "  
                            document['field2']  
                            " "  
                            document['field3']  
                            " "  
                            document['field4'],
                        textAlign: TextAlign.center,
                        style: TextStyle(
                            color: Colors.black,
                            fontWeight: FontWeight.bold,
                            fontSize: 18));
                  }).toList(),
                );
              },
            ),
          ],
        ));
  }
}
  • Related