-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6bc09b4
commit 797ec1d
Showing
13 changed files
with
361 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
example/lib/widgets/screen/catalog/dummy/sized_container.dummy.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/// AUTOGENERATED FILE. | ||
/// | ||
/// Use this file to prepare the preview and the tests: | ||
/// | ||
/// - SizedContainerPreview | ||
/// - SizedContainerTest | ||
/// - SizedContainerIntegrationTest | ||
/// | ||
import 'package:catalog/catalog.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
|
||
class SizedContainerDummy extends PreviewDummy { | ||
@override | ||
List<Dummy> get dummies => List.generate( | ||
8, | ||
(index) => Dummy( | ||
parameters: { | ||
'width': (index + 1) * 100.0, | ||
'child': Text(bigText * 4), | ||
}, | ||
), | ||
); | ||
} |
69 changes: 69 additions & 0 deletions
69
example/lib/widgets/screen/catalog/integration_test/sized_container_integration_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/// AUTOGENERATED FILE. | ||
/// | ||
/// Use this file to test the widget SizedContainer | ||
/// | ||
import 'package:catalog/catalog.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
|
||
import '../dummy/sized_container.dummy.dart'; | ||
import '../preview/sized_container.preview.dart'; | ||
|
||
class SizedContainerIntegrationTest { | ||
void main() { | ||
group( | ||
'SizedContainer - IntegrationTest Tests', | ||
() { | ||
testWidgets( | ||
'Child does not exceed the width', | ||
(tester) async { | ||
// prepare the context | ||
await tester.setupTestContext(); | ||
|
||
for (var dummy in SizedContainerDummy().dummies) { | ||
// prepare the widget | ||
final widget = buildSizedContainer(dummy); | ||
await tester.test(widget); | ||
|
||
// get the size of the widget | ||
final widgetSize = tester.getSize(find.byWidget(widget)); | ||
|
||
// check the maximum width | ||
expect( | ||
widgetSize.width, | ||
dummy.parameters['width'], | ||
); | ||
} | ||
}, | ||
); | ||
|
||
testWidgets( | ||
'Child does exceed the width', | ||
(tester) async { | ||
// prepare the context | ||
await tester.setupTestContext(); | ||
|
||
for (var dummy in SizedContainerDummy().dummies) { | ||
// prepare the widget | ||
final widget = Container( | ||
child: dummy.parameters['child'], | ||
); | ||
await tester.test(widget); | ||
|
||
// get the size of the widget | ||
final widgetSize = tester.getSize(find.byWidget(widget)); | ||
|
||
// check the maximum width | ||
expect( | ||
widgetSize.width, | ||
greaterThanOrEqualTo( | ||
dummy.parameters['width'], | ||
), | ||
); | ||
} | ||
}, | ||
); | ||
}, | ||
); | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
example/lib/widgets/screen/catalog/preview/sized_container.preview.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/// AUTOGENERATED FILE. DO NOT EDIT | ||
import 'package:catalog/catalog.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:example/widgets/screen/sized_container.dart'; | ||
import '../dummy/sized_container.dummy.dart'; | ||
|
||
@Preview( | ||
description: 'Container with a max width', | ||
parameters: ['width', 'child'], | ||
) | ||
class SizedContainerPreview extends ParentPreviewWidget { | ||
@override | ||
String get title => 'sized_container'; | ||
|
||
@override | ||
String get basePath => '/catalog'; | ||
|
||
const SizedContainerPreview({super.key}); | ||
|
||
@override | ||
Widget preview(BuildContext context) { | ||
Catalog().widgetBasicPreviewMap.clear(); | ||
Catalog().widgetDevicePreviewMap.clear(); | ||
|
||
if (SizedContainerDummy().dummies.isEmpty) { | ||
return Container(); | ||
} | ||
|
||
final deviceScreenshotsAvailable = | ||
SizedContainerDummy().deviceScreenshotsAvailable; | ||
final screenshotsAvailable = SizedContainerDummy().screenshotsAvailable; | ||
|
||
int basicScreenshots = screenshotsAvailable - deviceScreenshotsAvailable; | ||
|
||
return ListView( | ||
children: [ | ||
Column( | ||
children: [ | ||
if (basicScreenshots > 0) | ||
Center( | ||
child: Container( | ||
constraints: const BoxConstraints( | ||
maxWidth: 400, | ||
), | ||
child: Card( | ||
clipBehavior: Clip.hardEdge, | ||
child: Container( | ||
padding: const EdgeInsets.all(15), | ||
color: Colors.white, | ||
child: Row( | ||
children: [ | ||
Expanded( | ||
child: Center( | ||
child: Text( | ||
'$basicScreenshots basic screenshots available', | ||
), | ||
), | ||
), | ||
const IconButton( | ||
onPressed: processBasicScreenshots, | ||
icon: Icon( | ||
Icons.screenshot, | ||
), | ||
) | ||
], | ||
), | ||
), | ||
), | ||
), | ||
), | ||
if (deviceScreenshotsAvailable > 0) | ||
Center( | ||
child: Container( | ||
constraints: const BoxConstraints( | ||
maxWidth: 400, | ||
), | ||
child: Card( | ||
clipBehavior: Clip.hardEdge, | ||
child: Container( | ||
padding: const EdgeInsets.all(15), | ||
color: Colors.white, | ||
child: Row( | ||
children: [ | ||
Expanded( | ||
child: Center( | ||
child: Text( | ||
'$deviceScreenshotsAvailable device screenshots available', | ||
), | ||
), | ||
), | ||
const IconButton( | ||
onPressed: processDeviceScreenshots, | ||
icon: Icon( | ||
Icons.screenshot, | ||
), | ||
) | ||
], | ||
), | ||
), | ||
), | ||
), | ||
), | ||
for (int i = 0; i < SizedContainerDummy().dummies.length; i++) | ||
PreviewBoundary( | ||
widgetKey: GlobalKey(), | ||
dummyBuilder: () => SizedContainerDummy().dummies[i], | ||
builder: (BuildContext context, Dummy dummy) { | ||
return buildSizedContainer(dummy); | ||
}, | ||
), | ||
], | ||
) | ||
], | ||
); | ||
} | ||
} | ||
|
||
SizedContainer buildSizedContainer(Dummy dummy) { | ||
return SizedContainer( | ||
width: dummy.parameters['width'], | ||
child: dummy.parameters['child'], | ||
); | ||
} |
69 changes: 69 additions & 0 deletions
69
example/lib/widgets/screen/catalog/test/sized_container_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/// AUTOGENERATED FILE. | ||
/// | ||
/// Use this file to test the widget SizedContainer | ||
/// | ||
import 'package:catalog/catalog.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
|
||
import '../dummy/sized_container.dummy.dart'; | ||
import '../preview/sized_container.preview.dart'; | ||
|
||
class SizedContainerTest { | ||
void main() { | ||
group( | ||
'SizedContainer - Tests', | ||
() { | ||
testWidgets( | ||
'Child does not exceed the width', | ||
(tester) async { | ||
// prepare the context | ||
await tester.setupTestContext(); | ||
|
||
for (var dummy in SizedContainerDummy().dummies) { | ||
// prepare the widget | ||
final widget = buildSizedContainer(dummy); | ||
await tester.test(widget); | ||
|
||
// get the size of the widget | ||
final widgetSize = tester.getSize(find.byWidget(widget)); | ||
|
||
// check the maximum width | ||
expect( | ||
widgetSize.width, | ||
dummy.parameters['width'], | ||
); | ||
} | ||
}, | ||
); | ||
|
||
testWidgets( | ||
'Child does exceed the width', | ||
(tester) async { | ||
// prepare the context | ||
await tester.setupTestContext(); | ||
|
||
for (var dummy in SizedContainerDummy().dummies) { | ||
// prepare the widget | ||
final widget = Container( | ||
child: dummy.parameters['child'], | ||
); | ||
await tester.test(widget); | ||
|
||
// get the size of the widget | ||
final widgetSize = tester.getSize(find.byWidget(widget)); | ||
|
||
// check the maximum width | ||
expect( | ||
widgetSize.width, | ||
greaterThanOrEqualTo( | ||
dummy.parameters['width'], | ||
), | ||
); | ||
} | ||
}, | ||
); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'package:catalog/catalog.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
@Preview( | ||
description: 'Container with a max width', | ||
parameters: ['width', 'child'], | ||
) | ||
class SizedContainer extends StatelessWidget { | ||
final double width; | ||
final Widget child; | ||
|
||
const SizedContainer({ | ||
super.key, | ||
this.width = 500, | ||
required this.child, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) => Container( | ||
constraints: BoxConstraints( | ||
maxWidth: width, | ||
), | ||
child: child, | ||
); | ||
} |
Oops, something went wrong.