Firebse失败的断言:第380行pos 10:“ data!= null”

涡流
import 'package:flutter/material.dart';
import 'package:flutter_myapp/AllWidgets/Divider.dart';
import 'package:flutter_myapp/AllWidgets/progressDialog.dart';
import 'package:flutter_myapp/Assistants/requestAssistant.dart';
import 'package:flutter_myapp/DataHandler/appData.dart';
import 'package:flutter_myapp/Models/address.dart';
import 'package:flutter_myapp/Models/placePredictions.dart';
import 'package:flutter_myapp/configMaps.dart';
import 'package:provider/provider.dart';

class SearchScreen extends StatefulWidget {
  @override
  _SearchScreenState createState() => _SearchScreenState();
}

class _SearchScreenState extends State<SearchScreen>
{
  TextEditingController pickUpTextEditingController = TextEditingController();
  TextEditingController dropOffTextEditingController = TextEditingController();
  List<PlacePredictions> placePredictionList = [];


  @override
  Widget build(BuildContext context)
  {
    String placeAddress = Provider.of<AppData>(context).pickUpLocation.placeName ?? "";
    pickUpTextEditingController.text = placeAddress;

    return Scaffold(
      body: Column(
        children: [
          Container(
            height: 215.0,
            decoration: BoxDecoration(
              color: Colors.white,
              boxShadow: [
                BoxShadow(
                  color: Colors.black,
                  blurRadius: 6.0,
                  spreadRadius: 0.5,
                  offset: Offset(0.7, 0.7),
                ),
              ],
            ),

            child: Padding(
              padding: EdgeInsets.only(left: 25.0, top: 25.0, bottom: 20.0),
              child: Column(
                children: [

                  SizedBox(height: 5.0),
                  Stack(
                    children: [
                      GestureDetector(
                        onTap:()
                        {
                          Navigator.pop(context);

                        },
                        child: Icon(
                            Icons.arrow_back
                        ),
                      ),
                      Center(
                        child: Text("Set Drop Off", style: TextStyle(fontSize: 18.0, fontFamily: "Brand Bold"),),
                      )
                    ],

                  ),

                  SizedBox(height: 16.0),

                  Row(
                    children: [
                      Image.asset("images/pickicon.png", height: 16.0, width: 16.0,),

                      SizedBox(width: 18.0,),

                      Expanded(
                        child: Container(
                          decoration: BoxDecoration(
                            color:  Colors.grey[400],
                            borderRadius: BorderRadius.circular(5.0),
                          ),
                          child: Padding(
                            padding: EdgeInsets.all(3.0),
                            child: TextField(
                              controller: pickUpTextEditingController,
                              decoration: InputDecoration(
                                hintText: "PickUp Location",
                                fillColor: Colors.grey[400],
                                filled: true,
                                border: InputBorder.none,
                                isDense: true,
                                contentPadding: EdgeInsets.only(left: 11.0, top: 8.0, bottom: 8.0),
                              ),
                            ),
                          ),
                        ),

                      ),
                    ],
                  ),
                  SizedBox(height: 10.0),

                  Row(
                    children: [
                      Image.asset("images/desticon.png", height: 16.0, width: 16.0,),

                      SizedBox(width: 18.0,),

                      Expanded(
                        child: Container(
                          decoration: BoxDecoration(
                            color:  Colors.grey[400],
                            borderRadius: BorderRadius.circular(5.0),
                          ),
                          child: Padding(
                            padding: EdgeInsets.all(3.0),
                            child: TextField(
                              onChanged: (val)
                              {
                                findPlace(val);
                              },
                              controller: dropOffTextEditingController,
                              decoration: InputDecoration(
                                hintText: "Where to? ",
                                fillColor: Colors.grey[400],
                                filled: true,
                                border: InputBorder.none,
                                isDense: true,
                                contentPadding: EdgeInsets.only(left: 11.0, top: 8.0, bottom: 8.0),
                              ),
                            ),
                          ),
                        ),

                      ),
                    ],
                  ),
                ],
              ),
            ),
          ),

          //tile for predictions
          SizedBox(height: 10.0,),
          (placePredictionList.length > 0)
              ?Padding(
                 padding: EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
                 child: ListView.separated(
                   padding: EdgeInsets.all(0.0),
                   itemBuilder: (context, index)
                   {
                     return PredictionTile(placePredictions: placePredictionList[index],);
                   },
                   separatorBuilder: (BuildContext context, int index) => DividerWidget(),
                   itemCount: placePredictionList.length,
                   shrinkWrap: true,
                   physics: ClampingScrollPhysics(),
                 ),
                )
              :Container(),
        ],
      ),
    );
  }

  void findPlace(String placeName) async
  {
    if(placeName.length > 1)
    {
      String autoCompleteUrl = "https://maps.googleapis.com/maps/api/place/autocomplete/json?input=$placeName&key=$mapKey&sessiontoken=1234567890&components=country:us";

      var res = await RequestAssistant.getRequest(autoCompleteUrl);

      if(res == "failed")
      {
        return;
      }
      //print("Places Predictions Response :: ");
      //print(res);
      if(res["status"] == "OK")
      {
        var predictions = res["predictions"];

        var placeList = (predictions as List).map((e) => PlacePredictions.fromJson(e)).toList();

        setState(() {
          placePredictionList = placeList;
        });
      }
    }
  }
}



class PredictionTile extends StatelessWidget
{
  final PlacePredictions placePredictions;

  PredictionTile({Key key,this.placePredictions}) : super(key: key);


  @override
  Widget build(BuildContext context)
  {
    return FlatButton(
      padding: EdgeInsets.all(0.0),
      onPressed: ()
      {
        getPlaceAddressDetails(placePredictions.place_id, context);
      },
      child: Container(
        child: Column(
          children: [
            SizedBox(width: 10.0,),
            Row(
              children: [
                Icon(Icons.add_location),
                SizedBox(width: 14.0,),
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      SizedBox(height: 8.0,),
                      Text(placePredictions.main_text, overflow: TextOverflow.ellipsis, style: TextStyle(fontSize: 16.0),),
                      SizedBox(height: 2.0,),
                      Text(placePredictions.secondary_text, overflow: TextOverflow.ellipsis, style: TextStyle(fontSize: 12.0, color: Colors.grey),),
                      SizedBox(height: 8.0,),
                    ],
                  ),
                ),

              ],
            ),
            SizedBox(width: 10.0,),
          ],
        ),
      ),
    );
  }

  void getPlaceAddressDetails(String placeId, context) async
  {
    showDialog(
        context: context,
        builder: (BuildContext context) => ProgressDialog(message: "Setting Drop off, Please wait....",),
    );
    String placeDetailsUrl = "https://maps.googleapis.com/maps/api/place/details/json?place_id=$placeId&key=$mapKey";

    var res = await RequestAssistant.getRequest(placeDetailsUrl);
    Navigator.pop(context);
    if(res == "failed")
    {
      return;
    }
    if(res["status"] == "OK")
    {
      Address address = Address();
      address.placeName = res["result"]["name"];
      address.placeId = placeId;
      address.latitude = res["result"]["geometry"]["location"]["lat"];
      address.longitude = res["result"]["geometry"]["location"]["lng"];
      Provider.of<AppData>(context, listen: false).updateDropOffLocationAddress(address);
      print("This is Drop Off Location :: ");
      print(address.placeName);
      Navigator.pop(context, "obtainDirection");
    }
  }
}

请帮助我,我不明白怎么了。
我不断收到此错误。

小部件库捕获的异常:

构建PredictionTile(dirty)时引发了以下断言:必须将非null字符串提供给Text小部件。'package:flutter / src / widgets / text.dart':断言失败:380行pos 10:'data!= null'

斯特凡诺A.

Text Widget不能包含null数据,误差在以下行依赖:

 Text(placePredictions.main_text, overflow: TextOverflow.ellipsis, style: TextStyle(fontSize: 16.0),),
 Text(placePredictions.secondary_text, overflow: TextOverflow.ellipsis, style: TextStyle(fontSize: 12.0, color: Colors.grey),),

要解决此问题,我们可以将其更改为:

 Text(placePredictions.main_text ?? 'n/a', overflow: TextOverflow.ellipsis, style: TextStyle(fontSize: 16.0),),
 Text(placePredictions.secondary_text ?? 'n/a', overflow: TextOverflow.ellipsis, style: TextStyle(fontSize: 12.0, color: Colors.grey),),

这将null数据替换为“ n / a”。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

断言失败:第19行pos 16:'latitude!= null':不正确。颤动误差

来自分类Dev

Flutter错误-'package:flutter / src / painting / decoration_image.dart':断言失败:第50行pos 15:'image!= null':不正确

来自分类Dev

'package:flutter / src / painting / _network_image_io.dart':失败的断言:第25行pos 14:'url!= null':不正确

来自分类Dev

Flutter的'package:flutter / src / painting / _network_image_io.dart':失败的断言:第26行pos 16:'url!= null':不正确

来自分类Dev

断言失败预期:<Null>实际:<(null)>

来自分类Dev

'package:flutter / src / paintings / _network_image_io.dart':失败的断言:第25行优点14:'url!= null':不正确。

来自分类Dev

'package:flutter / src / paintings / _network_image_io.dart':失败的断言:第25行优点14:'url!= null':不正确。

来自分类Dev

NOT NULL 约束失败:instashot_data.user_id

来自分类Dev

断言失败:url!= null不正确

来自分类Dev

断言失败:行854位置14:'file!= null':不正确

来自分类Dev

UWP10的ViewModel属性为null

来自分类Dev

JSONObject在Android 10中返回null吗?

来自分类Dev

UWP10的ViewModel属性为null

来自分类Dev

Clearing data usage in windows 10

来自分类Dev

如何断言不为null?

来自分类Dev

MSSQL获取第10-20行

来自分类Dev

ENGINE = InnoDB'在SQL的第10行

来自分类Dev

第 10 行的“self”是可选的吗?

来自分类Dev

断言失败:布尔表达式不能为null异常

来自分类Dev

断言失败'url!= null':不正确错误

来自分类Dev

Flutter错误:失败的断言:1785行pos 12:'hasSize'

来自分类Dev

Sql-Data 基于10+ 万行的表中的datetime 列进行清除

来自分类Dev

第1行出现mysql错误'NULL'

来自分类Dev

Hartl的ROR第10章微博测试失败

来自分类Dev

Hartl ROR教程第10章Rspec测试失败

来自分类Dev

为什么以下代码打印出10而不是null?

来自分类Dev

为什么下面的代码打印出10而不是null?

来自分类Dev

device_data.get()始终返回Null

来自分类Dev

Windows 10启动失败

Related 相关文章

  1. 1

    断言失败:第19行pos 16:'latitude!= null':不正确。颤动误差

  2. 2

    Flutter错误-'package:flutter / src / painting / decoration_image.dart':断言失败:第50行pos 15:'image!= null':不正确

  3. 3

    'package:flutter / src / painting / _network_image_io.dart':失败的断言:第25行pos 14:'url!= null':不正确

  4. 4

    Flutter的'package:flutter / src / painting / _network_image_io.dart':失败的断言:第26行pos 16:'url!= null':不正确

  5. 5

    断言失败预期:<Null>实际:<(null)>

  6. 6

    'package:flutter / src / paintings / _network_image_io.dart':失败的断言:第25行优点14:'url!= null':不正确。

  7. 7

    'package:flutter / src / paintings / _network_image_io.dart':失败的断言:第25行优点14:'url!= null':不正确。

  8. 8

    NOT NULL 约束失败:instashot_data.user_id

  9. 9

    断言失败:url!= null不正确

  10. 10

    断言失败:行854位置14:'file!= null':不正确

  11. 11

    UWP10的ViewModel属性为null

  12. 12

    JSONObject在Android 10中返回null吗?

  13. 13

    UWP10的ViewModel属性为null

  14. 14

    Clearing data usage in windows 10

  15. 15

    如何断言不为null?

  16. 16

    MSSQL获取第10-20行

  17. 17

    ENGINE = InnoDB'在SQL的第10行

  18. 18

    第 10 行的“self”是可选的吗?

  19. 19

    断言失败:布尔表达式不能为null异常

  20. 20

    断言失败'url!= null':不正确错误

  21. 21

    Flutter错误:失败的断言:1785行pos 12:'hasSize'

  22. 22

    Sql-Data 基于10+ 万行的表中的datetime 列进行清除

  23. 23

    第1行出现mysql错误'NULL'

  24. 24

    Hartl的ROR第10章微博测试失败

  25. 25

    Hartl ROR教程第10章Rspec测试失败

  26. 26

    为什么以下代码打印出10而不是null?

  27. 27

    为什么下面的代码打印出10而不是null?

  28. 28

    device_data.get()始终返回Null

  29. 29

    Windows 10启动失败

热门标签

归档