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

#118 call _renderBoxInitialization in onPointerDown on trackbar #119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kainosk
Copy link

@kainosk kainosk commented Jul 20, 2021

This fixes #118

The cause of #118 is lack of calling _renderBoxInitialization method on onPointerDown callback. So I simply will call the method when trackbar's onPointerDown is called.

I confirmed this will fix #118 by below code:

import 'package:another_xlider/another_xlider.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Sample'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Builder(builder: (context) {
                return TextButton(
                  onPressed: () {
                    Navigator.of(context).push(
                      MaterialPageRoute(
                        builder: (context) => SliderView(),
                      ),
                    );
                  },
                  child:
                      Text('Show Slider View', style: TextStyle(fontSize: 30)),
                );
              }),
            ],
          ),
        ),
      ),
    );
  }
}

class SliderView extends StatefulWidget {
  @override
  _SliderViewState createState() => _SliderViewState();
}

class _SliderViewState extends State<SliderView> {
  double _sliderValue = 0.0;

  @override
  void initState() {
    super.initState();

    // To reproduce the bug,
    // the duration of `delayed` should be less than transition animation's duration (maybe 300ms).
    // For example, this demo uses 1ms.
    Future.delayed(Duration(milliseconds: 1)).then((_) {
      setState(() {
        _sliderValue = 50;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: SafeArea(
        child: Center(
          child: FlutterSlider(
            values: [_sliderValue],
            min: 0,
            max: 100,
          ),
        ),
      ),
    );
  }
}

Thank you ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong values are notified when changing value while transition.
1 participant