jonataslaw / getx

Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
MIT License
10.39k stars 1.63k forks source link

ScrollController offset not update immediately #2034

Open syssam opened 2 years ago

syssam commented 2 years ago

example:

class Controller extends GetxController {
  final ScrollController scrollController;
  final offset = 0.0.obs;
  @override
  void onReady() {
    scrollController.addListener(() {
        offset.value = scrollController.offset;
    });
   }
}
class Home extends StatelessWidget {
  final Controller controller = Get.find();
  @override
  Widget build(context) {
    return Scaffold(
      appBar: AppBar(title: Obx(() => Text("$offset"))),
      body: ListView.builder(
        controller: controller.scrollController,
        padding: const EdgeInsets.all(8),
        itemCount: 200,
        itemBuilder: (BuildContext context, int index) {
          return Container(
            height: 50,
            child: Center(child: Text("$index"),
          );
        }
      ),
    );
  }
}

Flutter Version: 2.5.1

Getx Version: ^4.3.8

Shreemanarjun commented 2 years ago

appdart controller

Please use the scroll controller in any scrollable widget, from where it can automatically trigger. May this will fix. Please update to latest Get version.

@jonataslaw Please close this

syssam commented 2 years ago

@jonataslaw sorry, wrong example. I update again

Shreemanarjun commented 2 years ago

@syssam use your logic inside onInit().

syssam commented 2 years ago

@Shreemanarjun I make a simple sample, it working. however, in the real case, it not working. image image image

jonataslaw commented 2 years ago

You need Wrap your widget with Obx()

syssam commented 2 years ago

image I wrap on outside

jonataslaw commented 2 years ago

You need to wrap the offset affected widget by an Obx

syssam commented 2 years ago

if use StatefulWidget and setState update offset, it seems more smooth.