首页 > 解决方案 > 如果 Condition 没有在内部调用

问题描述

以下代码中的我的 if 条件不起作用....

我认为我的 if 条件是错误的,但是代码应该调用 else 条件,但它没有这样做。

class polyline {
    List<LatLng> _listltlg=[];


    start_record() {
        BackgroundLocation.startLocationService();

        BackgroundLocation.getLocationUpdates((location) {

            if(_listltlg.isEmpty){
                print('2nd if statement');
                _listltlg.add(LatLng(location.latitude, location.longitude));

            }

            else{
                print('Else case');
            }
        });
    }

标签: flutterdartflutter-layout

解决方案


没错,第一次调用回调时,列表“_listltlg”为空。


推荐阅读