aws_appsync 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 63

Flutter AWS AppSync #

AWS AppSync plugin for Flutter, compatible with Flutter cognito plugin.

Features built-in: - Pagination - Caching using sembast

[0.0.1] - TODO: Add release date. #

  • TODO: Describe initial release.

example/lib/main.dart

import 'dart:async';
import 'dart:convert';

import 'package:aws_appsync/aws_appsync.dart';
import 'package:flutter/material.dart';
import 'package:flutter_json_widget/flutter_json_widget.dart';
import 'package:sembast/sembast_io.dart';
import 'package:super_logging/super_logging.dart';

import 'progress_mixin.dart';

void main() async {
  await SuperLogging.main();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        fontFamily: 'Courier',
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage>
    with ProgressMixin<MyHomePage> {
  final endpoint = TextEditingController(
    text:
        'https://kdsnweku3zbufknjcyda4arel4.appsync-api.ap-south-1.amazonaws.com/graphql',
  );
  final query = TextEditingController(
    text: r'''
query ListLessons(
  $filter: TableLessonFilterInput
  $limit: Int
  $nextToken: String
) {
  listLessons(filter: $filter, limit: $limit, nextToken: $nextToken) {
    items {
      sourceId
      chapterId
      chapterName
      chapterNumber
      colour
      curriculum
      grade
      lessonName
      lessonNumber
      pages
      pdfLanguage
      s3Key
      slides
      semester
      subject
      subjectSubtypes
      subjectSubtype
      updatedAt
      tags
      metadataOK
      potentialDuplicate
      duplicate
      password
    }
    nextToken
  }
}
''',
  );
  final variables = TextEditingController(text: '{}');
  final accessToken = TextEditingController();

  var results;
  var cacheEnabled = true;
  var priority = CachePriority.network;
  Duration timeTaken;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('AWS AppSync example'),
      ),
      body: SafeArea(
        child: Stack(
          children: <Widget>[
            ListView(
              padding: const EdgeInsets.all(16),
              children: <Widget>[
                TextField(
                  controller: endpoint,
                  decoration: InputDecoration(
                    labelText: 'endpoint',
                  ),
                ),
                TextField(
                  controller: query,
                  decoration: InputDecoration(
                    labelText: 'query',
                  ),
                  maxLines: null,
                ),
                TextField(
                  controller: variables,
                  decoration: InputDecoration(
                    labelText: 'variables',
                  ),
                  maxLines: null,
                ),
                TextField(
                  controller: accessToken,
                  decoration: InputDecoration(
                    labelText: 'accessToken',
                    hintText: 'You can copy this from flutter_cognito_plugin',
                  ),
                ),
                Divider(),
                CheckboxListTile(
                  value: cacheEnabled,
                  onChanged: (value) {
                    setState(() {
                      cacheEnabled = value;
                    });
                  },
                  title: Text('cache enabled'),
                ),
                if (cacheEnabled)
                  DropdownButton(
                    value: priority,
                    onChanged: (value) {
                      setState(() {
                        priority = value;
                      });
                    },
                    items: [
                      DropdownMenuItem(
                        value: CachePriority.network,
                        child: Text('${CachePriority.network}'),
                      ),
                      DropdownMenuItem(
                        value: CachePriority.cache,
                        child: Text('${CachePriority.cache}'),
                      )
                    ],
                  ),
                Divider(),
                Wrap(
                  alignment: WrapAlignment.center,
                  spacing: 16,
                  children: <Widget>[
                    RaisedButton(
                      child: Text('execute'),
                      onPressed: createOnPressed(execute),
                    ),
                    RaisedButton(
                      child: Text('paginate'),
                      onPressed: createOnPressed(paginate),
                    ),
                    RaisedButton(
                      child: Text('delete db'),
                      onPressed: createOnPressed(deleteDB),
                    ),
                  ],
                ),
                Divider(),
                Center(
                    child: Text(
                  'Results',
                  style: Theme.of(context).textTheme.title,
                )),
                if (timeTaken != null) Center(child: Text('(took $timeTaken)')),
                if (results is Map)
                  JsonViewerWidget(results)
                else if (results is List)
                  for (var result in results) JsonViewerWidget(result)
                else
                  Text("$results"),
              ],
            ),
            buildProgressStackWidget(),
          ],
        ),
      ),
    );
  }

  final appSync = AppSync();

  Future<dynamic> execute() async {
    return await appSync.execute(
      endpoint: endpoint.text.trim(),
      query: query.text,
      variables: jsonDecode(variables.text.trim()),
      accessToken: accessToken.text,
      cache: cacheEnabled ? await appSync.getCacheDatabase() : null,
      priority: priority,
    );
  }

  Future<dynamic> paginate() async {
    return appSync.paginate(
      endpoint: endpoint.text.trim(),
      query: query.text,
      variables: jsonDecode(variables.text.trim()),
      accessToken: accessToken.text,
      cache: cacheEnabled ? await appSync.getCacheDatabase() : null,
      priority: priority,
    );
  }

  Future<void> deleteDB() async {
    var db = await appSync.getCacheDatabase();
    await db.close();
    await databaseFactoryIo.deleteDatabase(db.path);
  }

  ProgressMixinTaskWrapper createOnPressed(ProgressMixinTask fn) {
    return wrapTask(() async {
      var s = DateTime.now();
      setState(() {
        timeTaken = null;
      });

      try {
        var data = await fn();
        if (data is Stream) {
          results = [];
          await for (var page in data) {
            if (!mounted) return;
            setState(() {
              results.add(page);
            });
          }
        } else {
          setState(() {
            results = data;
          });
        }
      } catch (e) {
        if (mounted) {
          setState(() {
            results = e;
          });
        }
      }

      setState(() {
        var e = DateTime.now();
        timeTaken = e.difference(s);
      });
    });
  }
}

Use this package as a library

1. Depend on it

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


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

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

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform Android

Because:

  • package:aws_appsync/aws_appsync.dart that imports:
  • package:path_provider/path_provider.dart that imports:
  • package:path_provider_linux/path_provider_linux.dart that declares support for platforms: Linux

Package does not support Flutter platform Web

Because:

  • package:aws_appsync/aws_appsync.dart that imports:
  • package:path_provider/path_provider.dart that declares support for platforms: Android, iOS, Linux, macOS

Package does not support Flutter platform Windows

Because:

  • package:aws_appsync/aws_appsync.dart that imports:
  • package:path_provider/path_provider.dart that declares support for platforms: Android, iOS, Linux, macOS

Package does not support Flutter platform iOS

Because:

  • package:aws_appsync/aws_appsync.dart that imports:
  • package:path_provider/path_provider.dart that imports:
  • package:path_provider_linux/path_provider_linux.dart that declares support for platforms: Linux

Package does not support Flutter platform macOS

Because:

  • package:aws_appsync/aws_appsync.dart that imports:
  • package:path_provider/path_provider.dart that imports:
  • package:path_provider_linux/path_provider_linux.dart that declares support for platforms: Linux

Package not compatible with SDK dart

Because:

  • aws_appsync that is a package requiring null.

Maintenance suggestions

The package description is too short. (-20 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.6.0 <3.0.0
crypto ^2.1.3 2.1.5
flutter 0.0.0
http ^0.12.1 0.12.1
logging ^0.11.4 0.11.4
path_provider ^1.6.7 1.6.11
sembast ^2.4.3 2.4.7+4
Transitive dependencies
charcode 1.1.3
collection 1.14.12 1.14.13
convert 2.1.1
file 5.2.1
http_parser 3.1.4
intl 0.16.1
meta 1.1.8 1.2.2
path 1.7.0
path_provider_linux 0.0.1+2
path_provider_macos 0.0.4+3
path_provider_platform_interface 1.0.2
pedantic 1.9.0 1.9.2
platform 2.2.1
plugin_platform_interface 1.0.2
process 3.0.13
sky_engine 0.0.99
source_span 1.7.0
string_scanner 1.0.5
synchronized 2.2.0+1
term_glyph 1.1.0
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
xdg_directories 0.1.0
Dev dependencies
flutter_test