GithubHelp home page GithubHelp logo

jack-beattie / flutterhomewidget Goto Github PK

View Code? Open in Web Editor NEW

This project forked from imreker/flutterhomewidget

0.0 0.0 0.0 8.4 MB

Flutter Home Widget app demonstrates how to create a home screen widget rendered by Flutter.

License: BSD 3-Clause "New" or "Revised" License

Java 22.90% Dart 8.38% C++ 40.53% Objective-C++ 0.53% Swift 16.95% C 6.45% Objective-C 1.15% Ruby 3.11%

flutterhomewidget's Introduction

Flutter Android/iOS/macOS Widget Example

This project demonstrates how to create an Android/iOS Home Widget or macOS Today Widget rendered by pure Flutter.

Previews

Previews Previews Previews

Introduction

All widget examples in this project are full functional, including widget configure and update.

iOS

Flutter engine on iOS takes too much memory and may only works on Simulator.

Render mode

This project uses 2 different of methods to render a widget.

1. UI Mode

In UI Mode, flutter engine is initialized with a separate main Dart function and run a separate App to display UI of widget.

The UI is rendered by the background renderer, a Bitmap of UI screenshot will be taken and show in the widget.

PROs:

Simple, write code as normal flutter app.

CONs:

Slow, Flutter side of runApp is slow, and a 200ms delay should be manually set after setState, because you have to wait for UI refresh. It can takes >6 seconds in Debug mode on an old Android phone. Fortunately, it only takes ~1 second in Release mode, so the speed is still acceptable.

2. Image Mode

In Image Mode, flutter engine is initialized with a separate main Dart function and listen a MethodChannel.

The handler of MethodChannel will draw a image by a dart Canvas and return the bytes array to native side.

When the widget request to update, it convert the bytes to Bitmap and show.

PROs:

Fast, only a few of codes is executed, bitmap is transferred via memory.

No need to wait for render, the image is drawn realtime.

Moreover, you can write your own Encoder of MethodChannel to boost the speed of the exchange of data.

CONs:

Difficult to write code, the whole content is drawn by Canvas.

flutterhomewidget's People

Contributors

imreker avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.