scaffold_list 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 75

scaffold_list #

A Flutter plugin that provides a scaffold for list.

Usage #

To use this plugin, add scaffold_list as a dependency in your pubspec.yaml file.

Example #

View example

0.0.1 #

  • Initial version.

0.0.2 #

  • Added example.

0.0.3 #

  • Some improvements.

0.0.4 #

  • Fixed empty list message.

0.0.5 #

  • Remove InkWell in search itemBuilder.

0.0.6 #

  • Added searchHintText & searchTheme params.

0.0.7 #

  • Now list default value is empty rather than null

0.0.8 #

  • Fixing some issues

0.0.9 #

  • Fixing some issues

0.1.0 #

  • list property now supports streams

0.1.1 #

  • Add isSearching method to state

example/lib/main.dart

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:scaffold_list/scaffold_list.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Scaffold List Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: ScaffoldListDemoPage(),
    );
  }
}

// Model Class
class Post {
  final int userId;
  final int id;
  final String title;
  final String body;

  Post({this.userId, this.id, this.title, this.body});

  factory Post.fromJson(Map<String, dynamic> json) => Post(
        userId: json['userId'],
        id: json['id'],
        title: json['title'],
        body: json['body'],
      );

  static List<Post> fromJsonList(List<dynamic> data) =>
      data.map((item) => Post.fromJson(item)).toList();
}

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

  final String title;

  @override
  _ScaffoldListDemoPageState createState() => _ScaffoldListDemoPageState();
}

class _ScaffoldListDemoPageState extends State<ScaffoldListDemoPage> {
  final _scaffoldKey = GlobalKey<ScaffoldState>();
  final _scaffoldListKey = GlobalKey<ScaffoldListState>();

  Future<List<Post>> _posts;

  @override
  void initState() {
    super.initState();
    _posts = _fetchPosts();
  }

  Future<List<Post>> _fetchPosts() async {
    final response =
        await http.get('https://jsonplaceholder.typicode.com/posts');

    if (response.statusCode == 200) {
      // If server returns an OK response, parse the JSON.
      return Post.fromJsonList(jsonDecode(response.body));
    } else {
      // If that response was not OK, throw an error.
      throw Exception('Failed to load posts');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldKey,
      appBar: AppBar(
        title: Text('Scaffold List Demo'),
        actions: <Widget>[
          IconButton(
            tooltip: MaterialLocalizations.of(context).searchFieldLabel,
            icon: Icon(Icons.search),
            onPressed: () async {
              // Open search delegate
              // Returns Future<Post> or null if closed
              final Post post =
                  await _scaffoldListKey.currentState.showSearch();

              if (post != null) {
                _scaffoldKey.currentState.showSnackBar(SnackBar(
                  content: Text("Selected post with id = ${post.id}"),
                ));
              }
            },
          )
        ],
      ),
      // Type must be passed as template for this example we are using `Post`
      body: ScaffoldList<Post>(
        // Use key to show search delegate
        key: _scaffoldListKey,
        // List can be Stream<List<Post>>, Future<List<Post>> or List<Post>
        list: _posts,
        // Build your item widget
        itemBuilder: (BuildContext context, Post post) => ListTile(
          title: Text(post.title),
          subtitle: Text(post.body),
          onTap: () {
            if (_scaffoldListKey.currentState.isSearching) {
              print("IS SEARCHING");
            } else {
              print("NOT SEARCHING");
            }
          },
        ),
        // Useaful when using Stream<List<T>> or Future<List<T>>
        filter: (Post post) => post.title.toLowerCase().startsWith("s"),
        // Also useaful when using Stream<List<T>> or Future<List<T>>
        sort: (Post postA, Post postB) =>
            postA.title.length.compareTo(postB.title.length),
        // Filter search results use key to show search delegate as shown above
        searchFilter: (Post post, String query) =>
            post.title.toLowerCase().contains(query.toLowerCase()),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


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

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

  • Dart: 2.8.2
  • pana: 0.13.8-dev
  • Flutter: 1.17.1

Maintenance suggestions

The package description is too short. (-4 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

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