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

make CapacityIndicator work with other values of splits, not only splits:10 #305

Merged
merged 18 commits into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example/lib/pages/indicators_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class _IndicatorsPageState extends State<IndicatorsPage> {
CapacityIndicator(
value: sliderValue,
onChanged: (v) => setState(() => sliderValue = v),
splits: 20,
discrete: true,
),
const SizedBox(height: 20),
Expand Down
4 changes: 2 additions & 2 deletions lib/src/indicators/capacity_indicators.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class CapacityIndicator extends StatelessWidget {
}

void _handleUpdate(Offset lp, double width) {
double value = (lp.dx / width) * splits;
double value = (lp.dx / width) * 100 / splits;
onChanged?.call(value.clamp(0.0, 100.0));
}

Expand All @@ -108,7 +108,7 @@ class CapacityIndicator extends StatelessWidget {
if (width.isInfinite) width = 100;
final splitWidth = width / splits;
if (discrete) {
final fillToIndex = value / splits - 1;
final fillToIndex = (value / 100) * splits - 1;
return SizedBox(
width: width,
child: GestureDetector(
Expand Down