搜尋分類、套件與程式碼儲存庫

screenshot_modes 封面
套件詳情v1.0.1

screenshot_modes

輕鬆自動為您的應用程式截圖,截圖模式作為 device_preview 套件的外掛模組運作

近 30 天下載
28
喜歡數
30
Pub 分數
60

安裝套件

flutter pub add screenshot_modes

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

Screenshot Modes 是一個 Flutter 套件,提供了一種簡單且自動化的方式,在您的應用中拍攝螢幕截圖。設計為 device_preview 套件的外掛,可讓開發人員在開發與測試過程中順暢地捕捉與管理螢幕截圖。透過將截圖功能直接整合至預覽環境中,提升工作流程,無需手動操作即可即時獲得視覺反饋。非常適合 UI 測試與設計驗證,簡化了在不同裝置與方向下記錄應用狀態的過程。

適用情境

  • UI 測試
  • 設計驗證
  • 跨裝置預覽
  • 自動截圖捕獲
  • 開發除錯

主要特色

  • 與 device_preview 的整合
  • 自動截圖捕獲
  • 支援多種裝置模式
  • 透過 pub 簡單設定
  • 即時預覽快照

適合對象

  • Flutter 開發者
  • UI/UX 設計師
  • 測試自動化工程師
  • 應用原型設計團隊
  • 品質保證測試人員

使用建議

  • 需要 device_preview 才能正常運行
  • 僅限開發環境
  • 無執行時截圖功能
  • 不適用於生產環境
  • 依賴於 device_preview 的更新

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

screenshot_modes

easy screenshot take for your app

screenshot_modes is a flutter package that work as a plugin for device preview package, take automatics screenshots for pages app

screenshot modes for Flutter gif

setup this plugin

0- you will need to setup device preview package first before using this plugin. it is just a few step.

simple mode :

  • simple mode you will just select device frame you want and function navigate to page and the plugin will make it work , will take screenshot for all your page in all frames in dark and light mode.

setup simple mode :

1- first define the plugin:

final simpleScreenShotModesPlugin = SimpleScreenShot(
  processor: saveScreenShot,
  pages: listPush,
  devices: [
    Devices.android.samsungGalaxyNote20.identifier,
    Devices.ios.iPhone13ProMax.identifier,
    Devices.ios.iPadAir4.identifier,
  ],
  lang: [Locale('ar') , Locale('en') ] ,
  useToggleDarkMode: true,
);

final listPush = [
  ItemScreenMode(function: pushHome, label: 'home'),
  ItemScreenMode(function: pushFirst, label: 'first'),
  ItemScreenMode(function: pushSecond, label: 'second'),
];

2- then pass it to device preview

  runApp(DevicePreview(
    builder: (_) => MyApp(),
    tools: [
      ...DevicePreview.defaultTools,
      simpleScreenShotModesPlugin
    ],
  ));

3- also define your push function ( pushHome,pushFirst,pushSecond) define for your page

Future pushHome(BuildContext context) async {
  Navigator.of(navigatorKey.currentContext)
      .push(DirectPageRouteBuilder(builder: (_) => HomePage()));
}

Future pushFirst(BuildContext context) async {
  Navigator.of(navigatorKey.currentContext)
      .push(DirectPageRouteBuilder(builder: (_) => FirstPage()));
}

Future pushSecond(BuildContext context) async {
  // we could get data from server;
  final data = await ApiService.getData();
  Navigator.of(navigatorKey.currentContext).push(DirectPageRouteBuilder(
      builder: (_) => SecondPage(
            nums: data,
          )));
}

it could be just Navigator or maybe call some api get data before Navigate like in pushSecond

4- define saveScreenShot function

this response for saving the image or upload it to some server or that ever you want to do with the image example to save the image in desktop folder

Future<String> saveScreenShot(DeviceScreenshotWithLabel screen) async {
  String name = screen.label.join('/');
  final path = join(Directory.current.path, 'screenshot', '$name.png');
  final imageFile = File(path);
  await imageFile.create(recursive: true);
  await imageFile.writeAsBytes(screen.deviceScreenshot.bytes);
  return '$path saved'; // message printed to device preview plugins windows;
}

5- click the new button(screenshot mode) in device preview tabs and that it.



______

advanced way ( simple way actually depend on it )

1- define ScreenShotModesPlugin

final screenShotModesPlugin =  ScreenShotModesPlugin(processor: saveScreenShot, modes: _modes );

2- pass screenShotModesPlugin to DevicePreview

void main() {
  runApp(DevicePreview(
    builder: (_) => MyApp(),
    tools: [
      ...DevicePreview.defaultTools,
      screenShotModesPlugin,
    ],
  ));
}

3- define saveScreenShot function this response for saving the image or upload it to some server or that ever you want to do with the image example to save the image in desktop

Future<String> saveScreenShot(DeviceScreenshotWithLabel screen) async {
  String name = screen.label.join('/');
  final path = join(Directory.current.path, 'screenshot', '$name.png');
  final imageFile = File(path);
  await imageFile.create(recursive: true);
  await imageFile.writeAsBytes(screen.deviceScreenshot.bytes);
  return '$path saved'; // message printed to device preview plugins windows;
}

4- add item to _modes list

  • simple way
final _modes_ = [
 ItemScreenMode(function: pushHome, label: 'home'),
 ItemScreenMode(function: pushFirst, label: 'first'),
 ItemScreenMode(function: pushSecond, label: 'second'),
];
  • with theme mode change

final listPush = [
  ItemScreenMode(function: pushHome, label: 'home'),
  ItemScreenMode(function: pushFirst, label: 'first'),
  ItemScreenMode(function: pushSecond, label: 'second'),
];

final _modes = [
  ItemScreenMode(
      function: (context) async {
        await setModeTo(context, ThemeMode.light);
      },
      label: "light",
      modes: listPush),
  ItemScreenMode(
      function: (context) async {
        await setModeTo(context, ThemeMode.dark);
      },
      label: "dark",
      modes: listPush),
];
  • with theme mode and device frame change
final _mode = [
  ItemScreenMode(
    function: setDeviceToIphone,
    label: "iphone",
    modes: listLightDark,
  ),
  ItemScreenMode(
      function: setDeviceToNote, label: "note", modes: listLightDark),
];
final listLightDark = [
  ItemScreenMode(
      function: (context) async {
        await setModeTo(context, ThemeMode.light);
      },
      label: "light",
      modes: listPush),
  ItemScreenMode(
      function: (context) async {
        await setModeTo(context, ThemeMode.dark);
      },
      label: "dark",
      modes: listPush),
];
final listPush = [
  ItemScreenMode(function: pushHome, label: 'home'),
  ItemScreenMode(function: pushFirst, label: 'first'),
  ItemScreenMode(function: pushSecond, label: 'second'),
];

Future<void> setDeviceToNote(BuildContext context) async {
  DevicePreviewHelper.changeDevice(
      context, Devices.android.samsungGalaxyNote20Ultra.identifier);
}

Future<void> setDeviceToIphone(BuildContext context) async {
  DevicePreviewHelper.changeDevice(context, Devices.ios.iPhone13.identifier)
}


you could benefid from DevicePreviewHelper class to change device , theme and other helper function

5- click the new button(screenshot mode) in device preview tabs



_______

what is ItemScreenMode :

it is represents every screenshot we will take

function parameter is a function that called before take screen we must navigate to the page you want take screenshot for it maybe also get some data from database or api before navigate

label parameter is string helps for naming the image inside processor (saveScreenShot)

modes parameter is another list of ItemScreenMode used if we have nested mode like light/dark for all pages and change frame for all pages like in above example



could i set function parameter for ItemScreenMode to null ?

yes when you don't need to do any things before first shot taken maybe when you already inside home page (defalut page) and in right themes mode tips : don't do that if you have multi nested page

why we must use DirectPageRouteBuilder for navigation

you must use DirectPageRouteBuilder for navigation like this

Future pushFirst() async {
  Navigator.of(navigatorKey.currentContext)
      .push(DirectPageRouteBuilder(builder: (_) => FirstPage()));

}

because the MaterialPageRoute have 500ms Duration for animations this will cause as a problem with screenshot so we must either use DirectPageRouteBuilder or await 500ms Duration after Navigation inside ItemScreenMode function

we prefers to use this plugin on desktop



TODO :

  • resizing the image for every mode ( so we could resized to the size required by google play or app store) ( now could done in saveScreenShot function )
  • improve the way for naming image .

所屬分類

依賴

依賴清單 3 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。