生成函数返回null。扑火基地

时间:2020-04-15 11:59:46

标签: firebase flutter dart

我尝试了很多事情,但是没有任何可行的解决方案,请帮忙。 即使使用FutureBuilder,它似乎也不起作用,没有它,当我热重装时,我会得到结果。我不知道如何更改代码以使其正常工作。可能有一些小的遗漏,但我仍无法弄清楚它是什么或如何解决。

SELECT ja.id, ja.title, COUNT(DISTINCT uskills.userID) as numUsers 
FROM job_areas ja
JOIN skill_types st ON ja.id = st.parent_id
JOIN user_skill_types uskills ON uskills.jobSkillID = st.id
GROUP BY ja.id, ja.title

2 个答案:

答案 0 :(得分:1)

使用 function SearchLocationResults(search) { $filter = new Array(); var leaseuid = null, complexuid = null; if (search == true) { if ($("#baseLocationViewModel_ComplexUId").data("kendoDropDownList").value() != '' && $("#baseLocationViewModel_ComplexUId").data("kendoDropDownList").value() != null && $("#baseLocationViewModel_ComplexUId").data("kendoDropDownList").value() != undefined) { $filter.push({ field: "Driver", operator: "isequalto", value: $("#baseLocationViewModel_DriverUId").data("kendoDropDownList").value() }); complexuid = $("#baseLocationViewModel_ComplexUId").data("kendoDropDownList").value(); } if ($("#baseLocationViewModel_MasterUId").data("kendoDropDownList").value() != '' && $("#baseLocationViewModel_MasterUId").data("kendoDropDownList").value() != null && $("#baseLocationViewModel_MasterUId").data("kendoDropDownList").value() != undefined) { $filter.push({ field: "LeaseUId", operator: "isequalto", value: $("#baseLocationViewModel_MasterUId").data("kendoDropDownList").value() }); leaseuid = $("#baseLocationViewModel_MasterUId").data("kendoDropDownList").value(); } } $(".loadermodel").removeClass('d-none'); $.ajax({ url: '/Keys/Keys/Grid_KeyLocationRead', type: "POST", dataType: "json", contentType: 'application/json; charset=utf-8', async: false, data: JSON.stringify({ request: $filter, schedule: $("#baseLocationViewModel_Schedule").val(), driver: $("#baseLocationViewModel_DriverUId").data("kendoDropDownList").value(), _complexUId: complexuid, _leaseUId: leaseuid }), cache: false, success: function (result) { $("#SearchResultsGridLocation").data('kendoGrid').dataSource.data([]); $("#SearchResultsGridLocation").data('kendoGrid').dataSource.data(result); $(".loadermodel").addClass('d-none'); }, error: function (err) { $(".loadermodel").addClass('d-none'); } }); } 函数时,您需要添加return关键字,因为它返回一个build

Widget

答案 1 :(得分:0)

对于遇到同样问题的人-这是我的完整代码!希望对您有帮助

import 'package:flutter/material.dart';
import 'package:list/screens/add_new_item_screen.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

final _firestore = Firestore.instance;
FirebaseUser loggedinUser;

Future<void> _fetchdata;

FirebaseAuth _auth = FirebaseAuth.instance;

class MainPage extends StatefulWidget {
  @override
  _MainPageState createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  void initState() {
    super.initState();

    _fetchdata = getCurrentUser();
  }

  Future<void> getCurrentUser() async {
    try {
      final user = await _auth.currentUser();
      if (user != null) {
        loggedinUser = user;
        // print(loggedinUser.email);
      }
    } catch (e) {
      print(e);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          Navigator.push(
              context, MaterialPageRoute(builder: (context) => Addnewitem()));
        },
        child: Icon(Icons.add),
      ),
      appBar: AppBar(
        leading: Container(),
        title: Text("Shopping List"),
        actions: <Widget>[
          IconButton(
              icon: Icon(Icons.close),
              onPressed: () {
                // messagesStream();
                _auth.signOut();
                Navigator.pop(context);
              })
        ],
      ),
      body: SafeArea(
        child: MessagesStream(),
      ),
    );
  }
}

class MessagesStream extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
        future: _fetchdata,
        builder: (context, myFuture) {
          if (myFuture.connectionState == ConnectionState.done &&
              !myFuture.hasError) {
            return StreamBuilder<QuerySnapshot>(
                stream: _firestore
                    .collection('users')
                    .document(loggedinUser.uid)
                    .collection('items')
                    .snapshots(),
                builder: (context, snapshot) {
                  if (!snapshot.hasData ||
                      snapshot.hasError ||
                      snapshot.data == null ||
                      snapshot.connectionState == ConnectionState.waiting ||
                      loggedinUser.email == null) {
                    return (Center(
                        child: CircularProgressIndicator(
                            backgroundColor: Colors.lightBlueAccent)));
                  }
                  final items = snapshot.data.documents.reversed;
                  List<MessageBubble> messageBubbles = [];
                  for (var message in items) {
                    final item = message.data['item'];

                    final quant = message.data['quant'];
                    final id = message.data['id'];
                    final boli = message.data['bool'];

                    // final currentUser = loggedinUser.email;

                    final messageBubble = MessageBubble(
                      text: item,
                      quant: quant,
                      documentReference: message.reference,
                    );

                    messageBubbles.add(messageBubble);
                  }
                  try {
                    return Expanded(
                      child: ListView(
                        // reverse: true,
                        padding:
                            EdgeInsets.symmetric(horizontal: 10, vertical: 10),
                        children: messageBubbles,
                      ),
                    );
                  } catch (e) {
                    return Container();
                  }
                });
          } else {
            return CircularProgressIndicator();
          }
        });
  }
}

class MessageBubble extends StatelessWidget {
  MessageBubble({this.text, this.quant, this.documentReference});

  final String text;
  final String quant;
  final DocumentReference documentReference;

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: Expanded(
        flex: 1,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            Container(
              color: Colors.tealAccent,
              child: FlatButton(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Text(
                        text,
                        style: TextStyle(color: Colors.black, fontSize: 20),
                      ),
                      Text(quant,
                          style: TextStyle(color: Colors.black, fontSize: 20))
                    ],
                  ),
                  onPressed: () {
                    documentReference.delete();
                  }),
            )
          ],
        ),
      ),
    );
  }
}