cupertino_list_tile 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • new68

Cupertino List Tile for Flutter #

pub license: BSD build codecov

Cupertino version of the stock Material ListTile in Flutter.

NOTE: This is not a pixel perfect interpretation of the iOS Human Interface Guidelines, but a quick and straight-forward adaptation of the Material ListTile to look a bit more appropriate with the Cupertino style, follow the appropriate color theme etc.

Preview #

CupertinoListTile

Usage #

To use this package, add cupertino_list_tile as a dependency in your pubspec.yaml file.

[0.1.0] - 2020-06-12 #

  • Initial release.

example/lib/main.dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart' show FlutterLogo;
import 'package:provider/provider.dart';
import 'package:cupertino_list_tile/cupertino_list_tile.dart';

void main() => runApp(
      ChangeNotifierProvider(
        create: (_) => ValueNotifier<Brightness>(Brightness.light),
        child: ExampleApp(),
      ),
    );

CupertinoNavigationBar buildNavigationBar(String title) {
  return CupertinoNavigationBar(
    middle: Text(title),
    trailing: Consumer<ValueNotifier<Brightness>>(
      builder: (context, brightness, child) {
        return CupertinoSwitch(
          value: brightness.value == Brightness.dark,
          onChanged: (value) =>
              brightness.value = value ? Brightness.dark : Brightness.light,
        );
      },
    ),
  );
}

class ExampleApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Consumer<ValueNotifier<Brightness>>(
      builder: (context, brightness, child) {
        return CupertinoApp(
          title: 'CupertinoListTile',
          debugShowCheckedModeBanner: false,
          theme: CupertinoThemeData(brightness: brightness.value),
          routes: {
            '/': (_) => HomePage(),
            '/one-line': (_) => TilePage(
                  title: 'One-line',
                  tileBuilder: (BuildContext context, String title) {
                    return CupertinoListTile(title: Text(title));
                  },
                ),
            '/one-leading': (_) => TilePage(
                  title: 'One-line with leading widget',
                  tileBuilder: (BuildContext context, String title) {
                    return CupertinoListTile(
                      leading: FlutterLogo(),
                      title: Text(title),
                    );
                  },
                ),
            '/one-trailing': (_) => TilePage(
                  title: 'One-line with trailing widget',
                  tileBuilder: (BuildContext context, String title) {
                    return CupertinoListTile(
                      title: Text(title),
                      trailing: Icon(CupertinoIcons.ellipsis),
                    );
                  },
                ),
            '/one-both': (_) => TilePage(
                  title: 'One-line with both widgets',
                  tileBuilder: (BuildContext context, String title) {
                    return CupertinoListTile(
                      leading: FlutterLogo(),
                      title: Text(title),
                      trailing: Icon(CupertinoIcons.ellipsis),
                    );
                  },
                ),
            '/two-line': (_) => TilePage(
                  title: 'Two-line',
                  tileBuilder: (BuildContext context, String title) {
                    return CupertinoListTile(
                      leading: FlutterLogo(size: 56.0),
                      title: Text(title),
                      subtitle: Text('Second line...'),
                    );
                  },
                ),
            '/three-line': (_) => TilePage(
                  title: 'Two-line',
                  tileBuilder: (BuildContext context, String title) {
                    return CupertinoListTile(
                      leading: FlutterLogo(size: 72.0),
                      title: Text('Three-line ListTile'),
                      subtitle: Text('Lorem ipsum\ndolor sit amet'),
                      isThreeLine: true,
                    );
                  },
                ),
          },
        );
      },
    );
  }
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
      navigationBar: buildNavigationBar('CupertinoListTile'),
      child: CupertinoScrollbar(
        child: ListView(
          children: [
            CupertinoListTile(
              title: Text('One-line'),
              onTap: () => Navigator.of(context).pushNamed('/one-line'),
            ),
            CupertinoListTile(
              title: Text('One-line with leading widget'),
              onTap: () => Navigator.of(context).pushNamed('/one-leading'),
            ),
            CupertinoListTile(
              title: Text('One-line with trailing widget'),
              onTap: () => Navigator.of(context).pushNamed('/one-trailing'),
            ),
            CupertinoListTile(
              title: Text('One-line with both widgets'),
              onTap: () => Navigator.of(context).pushNamed('/one-both'),
            ),
            CupertinoListTile(
              title: Text('Two-line'),
              onTap: () => Navigator.of(context).pushNamed('/two-line'),
            ),
            CupertinoListTile(
              title: Text('Three-line'),
              onTap: () => Navigator.of(context).pushNamed('/three-line'),
            ),
          ],
        ),
      ),
    );
  }
}

typedef TileBuilder = Widget Function(BuildContext context, String title);

class TilePage extends StatelessWidget {
  final String title;
  final TileBuilder tileBuilder;

  TilePage({Key key, this.title, this.tileBuilder});

  @override
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
      navigationBar: buildNavigationBar(title),
      child: CupertinoScrollbar(
        child: ListView.builder(
          itemCount: 20,
          itemBuilder: (BuildContext context, int index) {
            return tileBuilder(context, '$title #$index');
          },
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  cupertino_list_tile: ^0.1.0

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:cupertino_list_tile/cupertino_list_tile.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
36
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
68
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

because of import path [cupertino_list_tile] that is in a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
cupertino_icons ^0.1.3 0.1.3
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test
meta ^1.1.8 1.1.8