Merhaba , Flutter da yeniyim , öncelikle böyle bir forum sitesi ile sorularmızı Türkçe sorabilmek güzel olmuş , kuranların eline sağlık ..

Sorum ise udemy’den aldığım bir kursta null safety olmaksızın eğitim kaydı dinliyorum. şimdiye kadar bir şekilde sorunları açtım fakat son sorunu aşamadım yardımınızı istiyorum..

Uygulamada nul chech operator used ona null value hatası veriyor

nedeni ise ;

enSonGetirilenUser uygulamayı ilk açarken boş olması gerekiyor, boş olduğunda ise Null check operator used on a null value hatası alıyorum.

@override
Future<List<UserModel>> getUserWithPagination(UserModel? enSonGetirilenUser, int getirilecekElemanSayisi) async {



QuerySnapshot<Map<String, dynamic>>? _querySnapshot;

List<UserModel> _tumKullanicilar=[];

if (enSonGetirilenUser == null) {
  _querySnapshot = await FirebaseFirestore.instance
      .collection("users")
      .orderBy("userName")
      .limit(getirilecekElemanSayisi)
      .get();

  
} else {
  _querySnapshot = await FirebaseFirestore.instance
      .collection("users")
      .orderBy("userName")
      .startAfter([enSonGetirilenUser.userName])
      .limit(getirilecekElemanSayisi)
      .get();

  await Future.delayed(Duration(seconds: 1));
}

 for (DocumentSnapshot<Map<String, dynamic>> snap in _querySnapshot.docs) {
  UserModel _tekUser = UserModel.fromMap(snap.data());
  _tumKullanicilar.add(_tekUser);
}

return _tumKullanicilar;

}

    Bu sayfada yer alan

    List<UserModel> _users = await _userViewModel.getUserWithPagination(
    _enSonGetirilenUser!, _getirilecekElemanSayisi); bu kod parçasında hata alıyorum..

    // ignore_for_file: unnecessary_null_comparison

    import ‘dart:ui’;

    import ‘package:cloud_firestore/cloud_firestore.dart’;
    import ‘package:flutter/material.dart’;
    import ‘package:flutter/scheduler.dart’;
    import ‘package:flutter_lovers/app/sign_in/konusma.dart’;
    import ‘package:provider/provider.dart’;

    import ‘../model/user_model.dart’;
    import ‘../view_model/user_view_model.dart’;

    class KullanicilarPage extends StatefulWidget {
    const KullanicilarPage({Key? key}) : super(key: key);

    @override
    State<KullanicilarPage> createState() => _KullanicilarPageState();
    }

    class _KullanicilarPageState extends State<KullanicilarPage> {
    List<UserModel>? _tumKullanicilar;
    bool _isloading = false;
    bool _hasMore = true;
    int _getirilecekElemanSayisi = 11;
    UserModel? _enSonGetirilenUser;
    ScrollController _scroolController = ScrollController();

    @override
    void initState() {
    // TODO: implement initState
    super.initState();
    // getUSer2();
    SchedulerBinding.instance.addPostFrameCallback((_) {
    getUser();
    });
    scroolController.addListener(
    () {
    if (
    scroolController.position.atEdge) {
    if (_scroolController.position == 0) {
    print(“en tepedeyiz”);
    } else {
    getUser();
    }
    }
    },
    );
    }

    @override
    Widget build(BuildContext context) {
    final userViewModel = Provider.of<UserViewModel>(context, listen: false);
    //
    userViewModel.getAllUsers();

    return Scaffold(
        appBar: AppBar(
          title: const Text("Dalıcı Listesi"),
        ),
        body: _tumKullanicilar == null
            ? Center(child: CircularProgressIndicator())
            : _kullaniciListesiniOlustur());

    }

    Future getUser() async {
    final _userViewModel = Provider.of<UserViewModel>(context, listen: false);

    if (!_hasMore) {
      print("Getirilecek Eleman kalmadı");
      return;
    }
    
    setState(() {
      _isloading = true;
    });
    
    
    List<UserModel> _users = await _userViewModel.getUserWithPagination(
        _enSonGetirilenUser!, _getirilecekElemanSayisi);
    
    if (_tumKullanicilar == null) {
      _tumKullanicilar = [];
      _tumKullanicilar!.addAll(_users);
    } else {
      _tumKullanicilar!.addAll(_users);
    }
    
    if (_users.length < _getirilecekElemanSayisi) {
      _hasMore = false;
    }
    
    _enSonGetirilenUser = _tumKullanicilar?.last;
    
    setState(() {
      _isloading = false;
    });

    }

    _kullaniciListesiniOlustur() {
    return ListView.builder(
    controller: _scroolController,
    itemCount: _tumKullanicilar!.length + 1,
    itemBuilder: (context, index) {
    if (index == _tumKullanicilar!.length) {
    return yeniElemanlariYukleniyorIndicator();
    }
    return ListTile(
    title: Text(
    tumKullanicilar![index].userName!),
    );
    },
    );
    }

    _yeniElemanlariYukleniyorIndicator() {
    return Padding(
    padding: EdgeInsets.all(8),
    child: Center(
    child: Opacity(
    opacity: _isloading ? 1 : 0,
    child: _isloading ? CircularProgressIndicator() : null,
    ),
    ),
    );
    }
    }

      Write a Reply...