Orientação gerada a partir de informações públicas. Apenas para referência.
O pacote dual_screen fornece suporte do Flutter para dispositivos dobráveis e de tela dupla, permitindo que desenvolvedores criem interfaces do usuário adaptativas. Ele inclui o widget TwoPane para gerenciar layouts em duas telas e oferece acesso aos dados do sensor de ângulo de dobradiça, permitindo que os aplicativos respondam dinamicamente ao estado de dobramento do dispositivo. Projetado especificamente para Android, ajuda a criar experiências contínuas em dispositivos como o Surface Duo da Microsoft. O pacote se integra ao pipeline de renderização do Flutter para garantir transições suaves e layouts responsivos com base nas mudanças físicas no dispositivo.
Casos de uso
Construindo interfaces do usuário adaptativas para dispositivos dobráveis
Criando layouts de tela dividida com TwoPane
Respondendo a mudanças no ângulo de dobradiça
Otimizando o layout do aplicativo para telas duplas
Desenvolvendo padrões de navegação multi-janela
Principais recursos
Widget TwoPane para layouts de tela dupla
Integração de dados do sensor de ângulo da dobradiça
Suporte a dispositivos dobráveis específicos do Android
Adaptação dinâmica de layout
Desempenho nativo do Flutter
Indicado para
Desenvolvedores direcionados a dispositivos Android dobráveis
Aplicativos que exigem interface de tela dividida ou multi-janela
Equipes construindo para o Microsoft Surface Duo
Designers de interface focados em layouts adaptativos
Aplicativos multiplataforma que precisam de lógica de tela dupla
Considerações
Limitado à plataforma Android
Requer hardware compatível para teste
Pode ser necessário lógica de layout adicional para casos extremos
Depende da implementação dos sensores de dobradiça pelo fabricante do dispositivo
Não aplicável para dispositivos não dobráveis
README original
Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.
Flutter Dual Screen
This contains Microsoft's offerings to streamline foldable and dual-screen development using Flutter. This plugin will work on any platform, but only Android actually has foldable and dual screen devices.
Flutter already has support for foldable and dual-screen devices in the form of MediaQuery Display Features. In addition to that, this plugin offers:
The TwoPane widget, which relies on display features coming from MediaQuery.
Access to the hinge angle sensor data, which for performance concerns, was not included in MediaQuery.
TwoPane Widget
This layout has two child panes, which can be shown side-by-side, above-and-below, or a single pane can be prioritized. The relative size of the two pane widgets can be adjusted proportionally; and on dual-screen devices the boundary snaps to the hinge area.
startPane - Start pane, which can sit on the left for left-to-right layouts, or at the top for top-to-bottom layouts. If panePriority is start and there is no hinge, this is the only visible pane.
endPane - End pane, which can sit on the right for left-to-right layouts, or at the bottom for top-to-bottom layouts. If panePriority is end, and there is no hinge, this is the only visible pane.
paneProportion - Proportion of the screen occupied by the start pane. The end pane takes over the rest of the space. A value of 0.5 will make the two panes equal. This property is ignored for displays with a hinge, in which case each pane takes over one screen.
panePriority - Whether to show only one the start pane, end pane, or both. This property is ignored for displays with a hinge, in which case both panes are visible.
direction - Whether to stack the two panes verticaly or horizontaly, similar to Flex direction. This property is ignored for displays with a hinge, in which case the direction is horizontal for vertical hinges and vertical for horizontal hinges.
textDirection - When panes are laid out horizontally, this determines which one goes on the left. Behaves the same as Flex textDirection
verticalDirection - When panes are laid out vertically, this determines which one goes at the top. Behaves the same as Flex verticalDirection
padding - The padding between TwoPane and the edges of the screen. If there is spacing between TwoPane and the root MediaQuery, padding is used to correctly align the two panes to the hinge.
allowedOverrides - The parameters that TwoPane is allowed to override when a separating display feature is found. By default, it contains paneProportion, direction and panePriority, allowing all possible overrides.
Most of the parameters provided to TwoPane are ignored when the device has a hinge. This means that you can focus on how the layout works on large screens like tablets and desktops, while also having it adapt well to the dual-screen form factor by default.
This sample code produces the results at the beginning of this article:
On Surface Duo, widget A and widget B both take one screen.
On a tablet or desktop, widget A takes 30% of the screen while widget B takes the remaining 70%.
On a small phone which is less than 500 logical pixels wide, only widget A is visible.
Hinge angle sensor
Foldable and dual-screen devices have a hinge between the two moving parts of the screen. This hinge has a sensor, reporting the angle between the parts of the screen. For example, when these parts lay flat to form a continuous surface, the hinge angle reports a 180 deg angle.
The hinge angle is used to determine the device posture. If you're looking to write code that depends on the device posture, we recommend using the functionality provided by MediaQuery Display Features instead.
Hinge angle API
To use this plugin, add dual_screen as a dependency in your pubspec.yaml file.
This will allow you to import DualScreenInfo import 'package:dual_screen/dual_screen.dart';
DualScreenInfo exposes 2 static properties:
hingeAngleEvents: Broadcast stream of events from the device hinge angle sensor. If the device is not equipped with a hinge angle sensor, the stream produces no events.
hasHingeAngleSensor: Future returning true if the device has a hinge angle sensor. Alternatively, if your app already uses MediaQuery.displayFeatures or MediaQuery.hinge to adapt to foldable or dual-screen form factors, you can safely assume the hinge angle sensor exists and that hingeAngleEvents produces usable values.
Examples on how to mock the hinge angle or display features can be found in the test folder.
Testing the hinge angle sensor functionality can be done using the Surface Duo emulator or one of the foldable emulators available in Android Studio. Both emulators provide a hinge angle virtual sensor. The Surface Duo emulator is the only one with two separate screens.
Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct.
For more information see the Code of Conduct FAQ or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
Trademarks
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
trademarks or logos is subject to and must follow
Microsoft's Trademark & Brand Guidelines.
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
Any use of third-party trademarks or logos are subject to those third-party's policies.