forked from aloisdeniel/flutter_device_preview
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed SVG issues. Fixed enabled property. Updated documentation.
- Loading branch information
1 parent
3dceb4a
commit 231d793
Showing
33 changed files
with
357 additions
and
180 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import 'package:device_preview/device_preview.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class CustomPlugin extends StatelessWidget { | ||
const CustomPlugin({ | ||
Key? key, | ||
}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ToolPanelSection( | ||
title: 'Screenshot', | ||
children: [ | ||
ListTile( | ||
title: const Text('Print in console'), | ||
onTap: () { | ||
print('Hey, this is a custom plugin!'); | ||
}, | ||
) | ||
], | ||
); | ||
} | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,59 @@ | ||
# Writing your own plugin | ||
|
||
Making custom plugins can be really useful to add your own debugging tools. | ||
|
||
You can easily add a button to the tool bar that opens a window with your custom content. | ||
Making custom plugins can be really useful to add your own debugging tools to the device preview menu. | ||
|
||
## Define your plugin | ||
|
||
A plugin is nothing more than a regular [Sliver] that is added to the main Device Preview menu. | ||
|
||
To make things more aligned with built-in sections, you can add the `ToolPanelSection` widget and the `package:flutter/material.dart` widgets. | ||
|
||
```dart | ||
import 'package:device_preview/plugins.dart'; | ||
import 'package:device_preview/device_preview.dart'; | ||
import 'package:flutter/material.dart'; | ||
class CustomPlugin extends DevicePreviewPlugin { | ||
const CustomPlugin() : super( | ||
identifier: 'custom', // Unique identifier | ||
name: 'Custom', // Window's title | ||
icon: Icons.battery_unknown, // Button's icon | ||
windowSize: const Size(220, 220), // Window's size | ||
); | ||
class CustomPlugin extends StatelessWidget { | ||
const CustomPlugin({ | ||
Key? key, | ||
}) : super(key: key); | ||
@override | ||
Widget buildData( | ||
BuildContext context, | ||
Map<String, dynamic> data, // You plugin preferences (saved with other device preview's preferences) | ||
DevicePreviewPluginDataUpdater updateData, // update your plugin's data and triggers a rebuild. | ||
) { | ||
// Build the window's content here. | ||
return Center( | ||
child: Text('Hello !'), | ||
Widget build(BuildContext context) { | ||
return ToolPanelSection( | ||
title: 'Screenshot', | ||
children: [ | ||
ListTile( | ||
title: const Text('Print in console'), | ||
onTap: () { | ||
print('Hey, this is a custom plugin!'); | ||
}, | ||
) | ||
], | ||
); | ||
} | ||
} | ||
``` | ||
|
||
## Configure | ||
|
||
Add your plugin instance to your `DevicePreview`'s `plugins` property. | ||
 | ||
|
||
Add your plugin instance to your `DevicePreview`'s `tools` property. | ||
|
||
```dart | ||
DevicePreview( | ||
// ... | ||
plugins: [ | ||
tools: [ | ||
...DevicePreview.defaultTools, | ||
const CustomPlugin(), | ||
], | ||
), | ||
``` | ||
``` | ||
|
||
## Observing Device Preview's state | ||
|
||
If you need to check the current `DevicePreview` state, you can use one of the available methods : | ||
|
||
* `DevicePreview.isEnabled(BuildContext context)` : indicate whether the preview is currently enabled or not | ||
* `DevicePreview.selectedDevice(BuildContext context)` : get the currently selected device | ||
* `DevicePreview.locale(BuildContext context)` : get the currently selected locale |
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.