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

Set text color of selected segment #27

Closed
martijndierckx opened this issue Mar 3, 2023 · 1 comment
Closed

Set text color of selected segment #27

martijndierckx opened this issue Mar 3, 2023 · 1 comment

Comments

@martijndierckx
Copy link

How should I set the text color of the selected item?

@hadukin
Copy link
Owner

hadukin commented Mar 6, 2023

@martijndierckx hi, one way to do this

  int current = 0;

  @override
  Widget build(BuildContext context) {
    return CustomSlidingSegmentedControl<int>(
      isStretch: true,
      initialValue: 2,
      height: 24,
      children: {
        0: Text(
          'News daily portal',
          style: TextStyle(color: current == 0 ? Colors.red : Colors.black),
        ),
        1: Text(
          'Map',
          style: TextStyle(color: current == 1 ? Colors.red : Colors.black),
        ),
        2: Text(
          'Paper',
          style: TextStyle(color: current == 2 ? Colors.red : Colors.black),
        ),
      },
      decoration: BoxDecoration(
        color: CupertinoColors.lightBackgroundGray,
        borderRadius: BorderRadius.circular(8),
      ),
      thumbDecoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(6),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(.3),
            blurRadius: 4.0,
            spreadRadius: 1.0,
            offset: const Offset(
              0.0,
              2.0,
            ),
          ),
        ],
      ),
      duration: const Duration(milliseconds: 300),
      curve: Curves.easeInToLinear,
      onValueChanged: (v) {
        setState(() {
          current = v;
        });
      },
    );
  }

@hadukin hadukin closed this as completed Mar 6, 2023
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

No branches or pull requests

2 participants