Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Riverpod doesn't rebuild its widget correctly on MacOS when we start using other app windows. #3878

Open
stephane-archer opened this issue Dec 20, 2024 · 4 comments
Assignees
Labels
bug Something isn't working question Further information is requested

Comments

@stephane-archer
Copy link

Riverpod doesn't rebuild its widget correctly on MacOS when we start using other app windows.

output.mov
@rrousselGit
Copy link
Owner

I have no issue here. Any change you could make a minimal reproducible example? It could be that your app is the issue

@rrousselGit rrousselGit added question Further information is requested and removed needs triage labels Dec 20, 2024
@stephane-archer
Copy link
Author

stephane-archer commented Dec 20, 2024

Here is the code for reproducing the issue. just drop folder to the app.
It doesn't happens everytime, play with your browser and other app to see it happens

import 'dart:async';

import 'package:desktop_drop/desktop_drop.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

void main() {
  runApp(const ProviderScope(child: MyApp()));
}

final favoriteFoldersProvider = StateProvider<int>(
  (ref) => 0,
);

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends ConsumerWidget {
  const MyHomePage({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final favoriteFolders = ref.watch(favoriteFoldersProvider);
    return Scaffold(
      appBar: AppBar(),
      body: DropTarget(
        onDragDone: (dropDoneDetails) async {
          await _processDroppedFiles(
            dropDoneDetails,
            ref,
          );
        },
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(favoriteFolders.toString()),
            ],
          ),
        ),
      ),
    );
  }

  static Future<void> _processDroppedFiles(
    DropDoneDetails dropDoneDetails,
    WidgetRef ref,
  ) async {
    var files = dropDoneDetails.files;
    final filePaths = files.map((e) {
      return e.path;
    });
    if (filePaths.isEmpty) {
      return;
    }
    var favoriteFolders = ref.read(favoriteFoldersProvider.notifier);
    for (var i = 0; i < filePaths.length; i++) {
      favoriteFolders.update((state) {
        return state + 1;
      });
    }
  }
}

@rrousselGit
Copy link
Owner

That's too much code. Any change you could reproduce that with a simple counter?

@stephane-archer
Copy link
Author

stephane-archer commented Dec 20, 2024

@rrousselGit I can still observe this behavior with a simple counter. Can you reproduce this on your side?
I have updated the previous code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants