如何根据Firestore布尔值

时间:2019-05-28 09:48:43

标签: android flutter dart return flutter-layout

我想使用floatingButton函数的返回值来在HomePage中创建一个按钮。

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

abstract class AcountTypeManager{
    Widget floatingButton(BuildContext context);

}



class AcountElements implements AcountTypeManager{

    @override
    FloatingActionButton floatingButton(BuildContext context) {

     FloatingActionButton button = new FloatingActionButton();

     FirebaseAuth.instance.currentUser().then((user){

              FloatingActionButton buttonPacient = new FloatingActionButton(
              child: Icon(Icons.access_alarms),
              onPressed: (){
                print('test');
              }
              );


              FloatingActionButton buttonDoctor = new FloatingActionButton(
              child: Icon(Icons.calendar_today),
              onPressed: (){
                print('test');
              }
              );



      Firestore.instance
      .collection('/users')
      .where('uid', isEqualTo: user.uid)
      .getDocuments()
      .then((docs){
          if(docs.documents[0].exists){
            if(docs.documents[0].data['isDoctor'] == true){
              button = buttonDoctor;
              return button;
            }
            else
            {

              button = buttonDoctor;//button = buttonPacient;
              return button;
           }

           }
              button = buttonDoctor;
           return button;
      }
      );
    }
    );
    return button;
    }

}
</code>

首页:

class HomePageState extends State<HomePage>  {


  @override
  Widget build(BuildContext context) {

    FloatingActionButton button = new FloatingActionButton(onPressed: (){},);
    button = AcountElements().floatingButton(context);

       return Scaffold(

       floatingActionButton: button,

但是按钮似乎没有出现(只有我最初在floatingButton函数中声明的空按钮):

 FloatingActionButton button = new FloatingActionButton();

我是新手,我显然做错了什么。 有人可以帮我一个答案吗?

0 个答案:

没有答案