Skip to content

Commit

Permalink
version 2.2.2 changes:
Browse files Browse the repository at this point in the history
  * Fixed overflow issue when using minWidth: double.maxFinite
  * Code cleanups
  • Loading branch information
PramodJoshi committed Mar 21, 2024
1 parent 9f650c0 commit a158112
Show file tree
Hide file tree
Showing 9 changed files with 267 additions and 213 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## 2.2.2
* Fixed overflow [issue](https://github.com/PramodJoshi/toggle_switch/issues/79)
* Code cleanups

## 2.2.1
* updated version in README
* updated screenshot
* Updated version in README
* Updated screenshot

## 2.2.0
* Minor cleanups and fixes
Expand All @@ -16,7 +20,7 @@
* Added cancel toggle function ([PR 77](https://github.com/PramodJoshi/toggle_switch/pull/77/files)):
- function:
- cancelToggle: (index) {} (return type - Future\<bool>)
* Added these options [PR 74](https://github.com/PramodJoshi/toggle_switch/pull/74/files)):
* Added these options ([PR 74](https://github.com/PramodJoshi/toggle_switch/pull/74/files)):
- center text:
- centerText (optional, type bool - default false)
- multi-line text:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ In the `pubspec.yaml` of your flutter project, add the following dependency:
```yaml
dependencies:
...
toggle_switch: ^2.2.1
toggle_switch: ^2.2.2
```
Import it:
Expand Down
2 changes: 1 addition & 1 deletion example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ In the `pubspec.yaml` of your flutter project, add the following dependency:
```yaml
dependencies:
...
toggle_switch: ^2.2.1
toggle_switch: ^2.2.2
```
Import it:
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.1.0"
version: "2.2.2"
vector_math:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: example
description: An example application using toggle switch widget.
version: 2.2.1
version: 2.2.2
publish_to: none

environment:
Expand Down
1 change: 1 addition & 0 deletions lib/row_to_column.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';

/// A widget that displays its children in a row or column based on the value of isVertical (toggle switch type).
class RowToColumn extends StatelessWidget {
final List<Widget> children;
final bool isVertical;
Expand Down
407 changes: 202 additions & 205 deletions lib/toggle_switch.dart

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions lib/utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'package:flutter/material.dart';

class Utils {
/// Calculates width to prevent overflow by taking screen width into account.
/// Ignores customWidths if toggle switch is vertical
static double calculateWidth(
{required BuildContext context,
required int index,
required int totalSwitches,
List<double>? customWidths,
required double minWidth}) {
/// Extra width to prevent overflow and add padding
double extraWidth = 0.10 * totalSwitches;

/// Max screen width
double screenWidth = MediaQuery.of(context).size.width;

/// Returns width per label
///
/// Returns passed minWidth per label if total requested width plus extra width is less than max screen width.
/// Returns calculated width to fit within the max screen width if total requested width plus extra width is more than max screen width.
return customWidths != null
? customWidths[index]
: ((totalSwitches + extraWidth) * minWidth < screenWidth
? minWidth
: screenWidth / (totalSwitches + extraWidth));
}

/// Ignores customHeights if toggle switch is horizontal
static double calculateHeight(
{required BuildContext context,
required int index,
required int totalSwitches,
List<double>? customHeights,
required double minHeight}) {
/// Extra height to prevent overflow and add padding
double extraHeight = 0.10 * totalSwitches;

/// Max screen height
double screenHeight = MediaQuery.of(context).size.height;

/// Returns width per label
///
/// Returns passed minHeight per label if total requested width plus extra height is less than max screen height.
/// Returns calculated width to fit within the max screen width if total requested width plus extra height is more than max screen height.
return customHeights != null
? customHeights[index]
: ((totalSwitches + extraHeight) * minHeight < screenHeight
? minHeight
: screenHeight / (totalSwitches + extraHeight));
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: toggle_switch
description: Toggle Switch - A simple toggle switch widget. It can be fully customized with desired icons, width, colors, text, corner radius etc. It also maintains selection state.
version: 2.2.1
version: 2.2.2
homepage: https://github.com/PramodJoshi/toggle_switch

environment:
Expand Down

0 comments on commit a158112

Please sign in to comment.