Skip to content

Commit

Permalink
Merge pull request #34 from bamlab/fix/add-custom-device
Browse files Browse the repository at this point in the history
Fix/add custom device
  • Loading branch information
T-moz authored Sep 15, 2024
2 parents 61e17f2 + 1425df6 commit 06a831f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* **BREAKING**: feat: Add keyboardName to WindowConfigData
- fix: It's now possible to use custom devices as WindowConfigData variant
* feat: awaitImages now support FadeInImage.
* improvement: use pump instead of pumpAndSettle in awaitImages.
* feat: add path and version argument to expectGolden method.
Expand Down
9 changes: 8 additions & 1 deletion lib/src/adaptive/devices_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ enum _Device {
iPhone_13,
iPadPro,
desktop,
pixel_5,
pixel_5;

String get keyboardName => 'assets/keyboards/${this.name}.png';
}

/// [WindowConfigData] for an iPhone 8.
Expand All @@ -19,6 +21,7 @@ final WindowConfigData iPhone8 = WindowConfigData(
keyboardSize: const Size(375, 218),
borderRadius: BorderRadius.zero,
targetPlatform: TargetPlatform.iOS,
keyboardName: _Device.iPhone_8.keyboardName,
);

/// [WindowConfigData] for an iPhone 13.
Expand All @@ -34,6 +37,7 @@ final WindowConfigData iPhone13 = WindowConfigData(
homeIndicator: const HomeIndicatorData(8, Size(135, 5)),
notchSize: const Size(154, 32),
targetPlatform: TargetPlatform.iOS,
keyboardName: _Device.iPhone_13.keyboardName,
);

/// [WindowConfigData] for a Google Pixel 5.
Expand All @@ -49,6 +53,7 @@ final WindowConfigData pixel5 = WindowConfigData(
homeIndicator: const HomeIndicatorData(8, Size(72, 2)),
targetPlatform: TargetPlatform.android,
punchHole: const PunchHoleData(Offset(12, 12), 25),
keyboardName: _Device.pixel_5.keyboardName,
);

/// [WindowConfigData] for a 12.9" iPad Pro.
Expand All @@ -63,6 +68,7 @@ final WindowConfigData iPadPro = WindowConfigData(
),
homeIndicator: const HomeIndicatorData(8, Size(315, 5)),
targetPlatform: TargetPlatform.iOS,
keyboardName: _Device.iPadPro.keyboardName,
);

/// [WindowConfigData] for a basic 1080p web or desktop window.
Expand All @@ -73,4 +79,5 @@ final WindowConfigData desktop = WindowConfigData(
safeAreaPadding: EdgeInsets.zero,
borderRadius: BorderRadius.zero,
targetPlatform: TargetPlatform.linux,
keyboardName: _Device.desktop.keyboardName,
);
2 changes: 1 addition & 1 deletion lib/src/adaptive/widgets/layers/keyboard_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class _KeyboardDisplayerState extends State<KeyboardDisplayer> {
return Positioned(
bottom: 0,
child: Image.asset(
'assets/keyboards/${windowConfig.name}.png',
windowConfig.keyboardName,
height: windowConfig.keyboardSize?.height,
width: windowConfig.keyboardSize?.width,
package: 'adaptive_test',
Expand Down
5 changes: 5 additions & 0 deletions lib/src/adaptive/window_size.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class WindowConfigData extends Equatable {
required this.targetPlatform,
required this.borderRadius,
required EdgeInsets safeAreaPadding,
required this.keyboardName,
this.keyboardSize,
this.notchSize,
this.punchHole,
Expand Down Expand Up @@ -142,6 +143,9 @@ class WindowConfigData extends Equatable {
/// This represent the size of the device, expressed in `px`.
final Size physicalSize;

/// Name of the image asset that represent the keyboard.
final String keyboardName;

@override
List<Object?> get props => [
name,
Expand All @@ -156,6 +160,7 @@ class WindowConfigData extends Equatable {
viewInsets,
padding,
physicalSize,
keyboardName,
];
}

Expand Down

0 comments on commit 06a831f

Please sign in to comment.