Firestore Stream with Provider

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ธ.ค. 2024

ความคิดเห็น • 34

  • @ayeshafarrukh2567
    @ayeshafarrukh2567 ปีที่แล้ว

    Thank you so much for this video. It helped me a lot.

  • @wesleybarnes5376
    @wesleybarnes5376 4 ปีที่แล้ว +1

    Thank you for doing this!!

    • @tadaspetra
      @tadaspetra  4 ปีที่แล้ว

      Wesley Barnes thank you for watching!

  • @nick0c
    @nick0c 4 ปีที่แล้ว +1

    Very helpful. Thank you.

    • @tadaspetra
      @tadaspetra  4 ปีที่แล้ว

      nick0c glad to help!!

  • @SapinderSingh
    @SapinderSingh 2 ปีที่แล้ว

    Thank You So Much

  • @nguyenucthang9810
    @nguyenucthang9810 2 ปีที่แล้ว

    Thank you

  • @leozanchett
    @leozanchett 4 ปีที่แล้ว +1

    Thank you !

    • @tadaspetra
      @tadaspetra  4 ปีที่แล้ว +1

      No, thank you!

  • @burakbirer5938
    @burakbirer5938 3 ปีที่แล้ว +1

    Hi Tadas, what is the correct way to make a shopping cart with Firestore. I tried some approaches but many of them seemed quite inefficient to me. If we let user write the price then it will create a security problem. Anyone who might have bad intentions could easily manipulate the prices when writing to cart collection. And there is also a "paid custom options" problem. The only correct way is to create a cloud function? Would you mind making an episode for such situations? Thank you,

  • @tubetlamber
    @tubetlamber 4 ปีที่แล้ว +1

    Epic Tutorial! What song are you playing at the intro?

    • @tadaspetra
      @tadaspetra  4 ปีที่แล้ว +1

      Its called right here beside you
      th-cam.com/video/9V3dCGjupXU/w-d-xo.html

  • @danielh5112
    @danielh5112 3 ปีที่แล้ว

    Is it possible to stream an array inside of a collection? If it is I would love to see a video about it.
    Kind regards Daniel

  • @nickledesmac.786
    @nickledesmac.786 3 ปีที่แล้ว

    Thanks you

    • @tadaspetra
      @tadaspetra  3 ปีที่แล้ว

      Thank you for watching 😊

  • @free_intertaining
    @free_intertaining ปีที่แล้ว

    i did the same but at the first time it shows nothing but when i go back and then come back to the page it shows items

  • @nick0c
    @nick0c 4 ปีที่แล้ว +1

    I have a very similar use case where I am trying to stream a shopping list. But when I use the provider I get an error saying: type 'List' is not a subtype of type 'List... somehow the type is lost or something. If I change the type to List it all works but I don't that thats the proper solution. Any ideas?

    • @tadaspetra
      @tadaspetra  4 ปีที่แล้ว

      nick0c actually I think I know what it is. Are you reading the recipe from Firebase?
      If so Firebase returns a List you can map this to a List. Even if it’s not from Firebase wherever you retrieve the dynamic list just map it to a recipeitem list

    • @nick0c
      @nick0c 4 ปีที่แล้ว

      @@tadaspetra This is what I have - I thought I was doing that... Stream getPersonalList() {
      print('Fetching personal list');
      Stream _recipeItems =
      _db.collection('shopping_lists').document(userId).snapshots().map(
      (DocumentSnapshot documentSnapshot) =>
      documentSnapshot.data['list'].map((item) {
      // print(item);
      return RecipeItem(
      category: item['category'],
      wholeLine: item['wholeLine'],
      recipeTitle: item['recipeTitle'],
      recipeId: item['recipeId'],
      purchased: item['purchased'],
      );
      }).toList(),
      );
      return _recipeItems;
      }

    • @tadaspetra
      @tadaspetra  4 ปีที่แล้ว

      oh well, you are already mapping it to a List.
      So let me get this clear, you are using a StreamProvider, but you call this getPersonalList() function to start streaming it?
      If above is the case change the return type of the function to be StreamProvider and _recipeItems to the same type and it should work.

    • @nick0c
      @nick0c 4 ปีที่แล้ว

      @@tadaspetra Yeah you're correct thats actually where I started. It actually works with the first snip that I had dynamic in there. Terrible formatting here but if I do: Stream getPersonalList() {
      print('Fetching personal list');
      Stream _recipeItems =
      _db.collection('shopping_lists').document(userId).snapshots().map(
      (DocumentSnapshot documentSnapshot) =>
      documentSnapshot.data['list'].map((item) {
      // print(item);
      return RecipeItem(
      category: item['category'],
      wholeLine: item['wholeLine'],
      recipeTitle: item['recipeTitle'],
      recipeId: item['recipeId'],
      purchased: item['purchased'],
      );
      }).toList(),
      );
      return _recipeItems;
      } and then in main.dart ---> class MyApp extends StatelessWidget {
      // This widget is the root of your application.
      @override
      Widget build(BuildContext context) {
      return MultiProvider(
      providers: [
      StreamProvider(
      //Access withing the app -> var user = Provider.of(context);
      create: (_) => AuthService().user),
      StreamProvider(
      create: (_) => PersonalListDB().getPersonalList(),
      catchError: (context, error) {
      print(
      'This is the error from stream provider in main screen *** $error');
      },
      ),
      ChangeNotifierProvider(
      create: (_) => RecipesDB(),
      )
      ],
      child: MaterialApp( ... I still get the same error.

    • @tadaspetra
      @tadaspetra  4 ปีที่แล้ว

      Stream getPersonalList() {
      print('Fetching personal list');
      This first line in the function definition. Make that type Stream

  • @gilangluthfiajimuzaki9300
    @gilangluthfiajimuzaki9300 4 ปีที่แล้ว +1

    Hi, nice tutorial. Can you make a tutorial on how to retrieve a data, base on the user uid when they login to create a user profile?
    I have looking at so many tutorials but I always got an error.

    • @tadaspetra
      @tadaspetra  4 ปีที่แล้ว

      Gilang Luthfi Aji Muzaki I actually have a video similar to what you’re looking for in the “Book Club App” playlist. It’s a playlist about creating a complete app. And it does something similar

    • @gilangluthfiajimuzaki9300
      @gilangluthfiajimuzaki9300 4 ปีที่แล้ว

      @@tadaspetra yes I watch this tutorial no #8, But it does not show how you can put the user information into the UI. I've been trying using the the streambuilder method but i got null result.

    • @tadaspetra
      @tadaspetra  4 ปีที่แล้ว +1

      Gilang Luthfi Aji Muzaki wherever you call to retrieve the userState do a setState after it. The data will be null at first, but it should load up once it is retrieved. Make sure you use a stateful widget too.
      If you look at the app in most recent github in screens/inGroup/secondCard uses the userState, could be helpful

  • @abaidshareef3594
    @abaidshareef3594 4 ปีที่แล้ว

    when i accessing data with stream from firebase database where the data is in collection->document->collection ... im unable to retrive data ... can u help me with it