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

Dynamic height with scrollable for custom length of steps #31

Open
pratikbutani opened this issue Jul 6, 2021 · 2 comments
Open

Dynamic height with scrollable for custom length of steps #31

pratikbutani opened this issue Jul 6, 2021 · 2 comments
Labels
question Further information is requested

Comments

@pratikbutani
Copy link

I am using verticle StepProgressIndicator and I want to give dynamic height to it because I am generating steps based on the length of API.

Is there any way to give height dynamically with a scrollable list of indicators?

@kevin4dhd
Copy link

any solution?

@SandroMaglione
Copy link
Owner

Hi @pratikbutani (cc @kevin4dhd)

The height of each step with StepProgressIndicator is computed based on the parent container size. Therefore, if you want the size of the each step to change based on a dynamic value, you should change the height of the container.

Below an example:

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: const [
            Box(height: 100),
            Box(height: 200),
            Box(height: 300),
            Box(height: 400),
            Box(height: 500),
          ],
        ),
      ),
    );
  }
}

class Box extends StatelessWidget {
  final double height;
  const Box({
    Key? key,
    required this.height,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        border: Border.all(
          color: Colors.black,
          width: 2,
        ),
      ),
      width: 100,
      height: height,
      child: const Indicator(),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return const StepProgressIndicator(
      totalSteps: 10,
      currentStep: 5,
      size: 20,
      direction: Axis.vertical,
    );
  }
}

Screenshot 2022-01-02 at 15 31 49


The principle is the same if your parent container is scrollable:

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: SizedBox(
          height: 300,
          child: SingleChildScrollView(
            scrollDirection: Axis.vertical,
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: const [
                Box(height: 500),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

class Box extends StatelessWidget {
  final double height;
  const Box({
    Key? key,
    required this.height,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        border: Border.all(
          color: Colors.black,
          width: 2,
        ),
      ),
      width: 100,
      height: height,
      child: const Indicator(),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return const StepProgressIndicator(
      totalSteps: 10,
      currentStep: 5,
      size: 20,
      direction: Axis.vertical,
    );
  }
}

Screenshot 2022-01-02 at 15 37 19

@SandroMaglione SandroMaglione added the question Further information is requested label Jan 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants