Skip to content

Commit

Permalink
refactor: example app (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
KoheiKanagu authored Jun 9, 2024
1 parent 95ec28d commit fdd1f42
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 59 deletions.
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ final previewDevices = [
runApp(
MediaQueryPreview(
previewDevices: previewDevices,
builder: (_, previewDevice) => UncontrolledProviderScope(
container: ProviderContainer(
parent: container,
),
child: MyApp(
targetPlatform: previewDevice.targetPlatform,
),
),
builder: (_, previewDevice) {
// If you want to change the theme based on the targetPlatform,
// you can get the targetPlatform from [previewDevice.targetPlatform].
return UncontrolledProviderScope(
container: container,
child: const MyApp(),
);
},
),
);
```
Expand All @@ -91,9 +91,11 @@ If you are not using [riverpod](https://pub.dev/packages/riverpod), it is even s
runApp(
MediaQueryPreview(
previewDevices: previewDevices,
builder: (_, previewDevice) => MyApp(
targetPlatform: previewDevice.targetPlatform,
),
builder: (_, previewDevice) {
// If you want to change the theme based on the targetPlatform,
// you can get the targetPlatform from [previewDevice.targetPlatform].
return const MyApp();
},
),
);
```
Expand Down
30 changes: 15 additions & 15 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ void main() {
// if (kReleaseMode) {
// runApp(
// UncontrolledProviderScope(
// container: ProviderContainer(
// parent: container,
// ),
// container: container,
// child: const MyApp(
// targetPlatform: TargetPlatform.iOS,
// ),
Expand Down Expand Up @@ -64,24 +62,26 @@ void main() {
runApp(
MediaQueryPreview(
previewDevices: previewDevices,
builder: (_, previewDevice) => UncontrolledProviderScope(
container: ProviderContainer(
parent: container,
),
child: MyApp(
targetPlatform: previewDevice.targetPlatform,
),
),
builder: (_, previewDevice) {
// If you want to change the theme based on the targetPlatform,
// you can get the targetPlatform from [previewDevice.targetPlatform].
return UncontrolledProviderScope(
container: container,
child: const MyApp(),
);
},
),
);

// If you don't use riverpod, do like this
// If you are not using riverpod, it is even simpler.
// runApp(
// MediaQueryPreview(
// previewDevices: previewDevices,
// builder: (_, previewDevice) => MyApp(
// targetPlatform: previewDevice.targetPlatform,
// ),
// builder: (_, previewDevice) {
// // If you want to change the theme based on the targetPlatform,
// // you can get the targetPlatform from [previewDevice.targetPlatform].
// return const MyApp();
// },
// ),
// );
}
7 changes: 3 additions & 4 deletions example/lib/my_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ class CounterController extends _$CounterController {

class MyApp extends StatelessWidget {
const MyApp({
required this.targetPlatform,
super.key,
});

final TargetPlatform targetPlatform;

@override
Widget build(BuildContext context) {
return MaterialApp(
Expand All @@ -43,7 +40,9 @@ class MyApp extends StatelessWidget {
),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
home: const MyHomePage(
title: 'Flutter Demo Home Page',
),
);
}
}
Expand Down
8 changes: 2 additions & 6 deletions example/test/my_app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,8 @@ void main() {
]
],
builder: (_, previewDevice) => UncontrolledProviderScope(
container: ProviderContainer(
parent: container,
),
child: MyApp(
targetPlatform: previewDevice.targetPlatform,
),
container: container,
child: const MyApp(),
),
);

Expand Down
41 changes: 18 additions & 23 deletions lib/src/preview_table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,25 @@ class PreviewTable extends StatelessWidget {
child: TableView.builder(
columnCount: previewDevices.map((e) => e.length).reduce(max),
rowCount: previewDevices.length,
columnBuilder: (index) => TableSpan(
extent: FixedTableSpanExtent(
previewDevices.map(
(e) {
if (e.length <= index) {
return 0.0;
}
return e[index].size.width;
},
).reduce(max),
),
),
rowBuilder: (index) {
final double extent;
columnBuilder: (index) {
final extent = previewDevices
.map(
(e) => e.length > index ? e[index].size.width : 0.0,
)
.reduce(max);

if (previewDevices.length <= index) {
extent = 0.0;
} else {
extent = previewDevices[index]
.map(
(e) => e.size.height,
)
.reduce(max);
}
return TableSpan(
extent: FixedTableSpanExtent(extent),
);
},
rowBuilder: (index) {
final extent = previewDevices.length > index
? previewDevices[index]
.map(
(e) => e.size.height,
)
.reduce(max)
: 0.0;

return TableSpan(
extent: FixedTableSpanExtent(extent),
Expand Down

0 comments on commit fdd1f42

Please sign in to comment.