supabase / supabase-flutter

Flutter integration for Supabase. This package makes it simple for developers to build secure and scalable products.
https://supabase.com/
MIT License
703 stars 167 forks source link

Stream() doesn't work when a date type column is used to filter. #99

Closed IvanHerreraCasas closed 1 year ago

IvanHerreraCasas commented 2 years ago

Bug report

Describe the bug

Hi when a date type column is used to listen for specific rows in the table, it just sends the data once (as a normal select method).

It works normally when listening to all the rows or with an int2 type column.

To Reproduce

Here is a minimum reproducible code

import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:supabase_flutter/supabase_flutter.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Supabase.initialize(
    url: 'my_url',
    anonKey: '''my_key''',
  );
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Column(
        children: [
          // when the stream doesn't seem to work (when date is used to filter)
          // I use this and it shows the new data, so the behavior is like a normal get and not a realtime.
          ElevatedButton(
            onPressed: () {
              setState(() {});
            },
            child: const Text('Refresh'),
          ),
          Expanded(
            child: Center(
              child: StreamBuilder(
                // this works
                // stream: Supabase.instance.client
                // .from('table')
                // .stream(['id']).execute(),

                // this works
                // stream: Supabase.instance.client
                // .from('table:type=eq.0')
                // .stream(['id']).execute(),

                // this doesn't work
                stream: Supabase.instance.client
                    .from(
                        'table:date=eq.${DateFormat('MM/dd/yyyy').format(DateTime(2022, 04, 24))}')
                    .stream(['id']).execute(),
                builder: (BuildContext context,
                    AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
                  if (snapshot.hasError) {
                    return Text(snapshot.error.toString());
                  } else if (snapshot.connectionState ==
                      ConnectionState.waiting) {
                    return const CircularProgressIndicator();
                  } else if (snapshot.hasData) {
                    return Column(
                      children: snapshot.data!
                          .map((e) =>
                              Text('name: ${e['name']} --- date: ${e['date']}'))
                          .toList(),
                    );
                  }
                  return const Text('other');
                },
              ),
            ),
          ),
        ],
      ),
    );
  }
}

Screenshots

Here is the table definition (it's name is 'table') table

Also replication is enabled for all the tables replication

dshukertjr commented 2 years ago

Thank you for creating such detailed issue. We are looking into this issue and will get back with a fix hopefully soon.

dshukertjr commented 1 year ago

I was able to confirm that this works in yyyy/MM/dd format or yyyy-MM-dd format like this.

supabase
   .from('random')
   .stream(primaryKey: ['id'])
   .gte('date_type_column', '2023/01/01');