adaptable_widget 0.2.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 67

adaptable_widget #

A collection of widgets that adapt to match the preferred style of the current platform

Why? #

Flutter is a great development platform, but often different platforms require different UI components to match the style the user is most familiar with (i.e. Material on Android and Cupertino on iOS). This platform aims to make detecting and switching between those platforms as simple as throwing it in another widget that does all the work.

Getting Started #

The simplest use case is just the AdaptableWidget:

Widget build() {
  return AdaptableWidget(
    android: AndroidWidget(...),
    ios: CupertinoWidget(...),
    fuschia: FuschiaWidget(...),
    windows: WindowsWidget(...), //Currently not supported
    macos: MacOSWidget(...), //Currently not supported
    web: WebWidget(...), //Support coming soon

Other Widgets #

These other widgets wrap the AdaptableWidget to provide common-use-case adaptations with less boilerplate.

AdaptableApp #

This is an easy way to switch between MaterialApp and CupertinoApp so that the material and cupertino widgets have the proper ancestors.


Widget build() {
  return AdaptableApp(
    title: "My App",
    materialTheme: ThemeData(...),
    cupertinoTheme: CupertinoThemeData(...),
    home: MyHomePage(...),

AdaptableScaffold #

The aim of AdaptableScaffold is to switch between Scaffold or CupertinoScaffoldPage without having to write the child UI code twice.


Widget build() {
  return AdaptableScaffold(
    child: MyHomePage(), //Required
    appBar: AppBar(...),
    cupertinoNavigationBar: cupertinoNavigationBar(...),
    backgroundColor: Colors.white,
    resizeToAvoidBottomInset: true,

AdaptableButton #

Buttons are one Widget that often have a certain look and feel on different platforms. This AdaptableButton class provides simply a child and an onPressed callback.


Widget build() {
  return AdaptableButton(
    child: Text("Tap Me!"),
    onPressed: doSomething,

AdaptableTextField #

Switches between TextField and CupertinoTextField based on the platform.

Helper Functions #

adaptableTextStyle #

This function returns a TextStyle or based on the Platform.

[0.2.1] - May 27, 2019 #

  • Add decoration properties to AdaptableTextField widget.

[0.2.0] - May 27, 2019 #

  • Make AdaptableWidget stateful.

[0.1.4] - May 27, 2019 #

  • Add AdaptableText widget.

[0.1.3] - May 27, 2019 #

  • Add adaptableTextStyle function.

[0.1.2] - May 25, 2019 #

  • Add AdaptableTextField widget.

[0.1.1] - May 25, 2019 #

  • Add AdaptableApp widget.

[0.1.0] - May 25, 2019 #

  • Initial release


import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:adaptable_widget/adaptable_widget.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  Widget build(BuildContext context) {
    return AdaptableApp(
      title: 'Flutter Demo',
      materialTheme: ThemeData(
        textTheme: TextTheme(
          title: TextStyle(
            color: Colors.tealAccent,
      cupertinoTheme: CupertinoThemeData(
        textTheme: CupertinoTextThemeData(

      home: MyHomePage(title: 'Flutter Demo Home Page'),

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  _MyHomePageState createState() => _MyHomePageState();

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.

  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return AdaptableScaffold(
      cupertinoNavigationBar: CupertinoNavigationBar(
        middle: Text(widget.title),
        trailing: CupertinoButton(
          onPressed: _incrementCounter,
          child: Icon(CupertinoIcons.add_circled_solid),
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the method, and use it to set our appbar title.
        title: Text(widget.title),
      child: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          // Column is also layout widget. It takes a list of children and
          // arranges them vertically. By default, it sizes itself to fit its
          // children horizontally, and tries to be as tall as its parent.
          // Invoke "debug painting" (press "p" in the console, choose the
          // "Toggle Debug Paint" action from the Flutter Inspector in Android
          // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
          // to see the wireframe for each widget.
          // Column has various properties to control how it sizes itself and
          // how it positions its children. Here we use mainAxisAlignment to
          // center the children vertically; the main axis here is the vertical
          // axis because Columns are vertical (the cross axis would be
          // horizontal).
          children: <Widget>[
              'You have pushed the button this many times:',
              style: adaptableTextStyle(
                material: MaterialTextTheme.display1,
                cupertino: CupertinoTextTheme.navLargeTitleTextStyle,
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  adaptable_widget: ^0.2.1

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:adaptable_widget/adaptable_widget.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Apr 1, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies