mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 22:09:06 +00:00
* add web_dashboard sample * add docs * address code review comments * restructure web_dashboard * set up provider and mock service * add copyright headers, use relative imports * add API class, add tests * fmt * rename services -> API, remove data library * use new API in app * add stream to items api * convert from StreamBuilder to StreamProvider * add subscription to Entry API * rename API classes * address comments * Update README.md * update README * remove routing_demo
46 lines
1.1 KiB
Dart
46 lines
1.1 KiB
Dart
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
/// Manipulates app data,
|
|
abstract class DashboardApi {
|
|
ItemApi get items;
|
|
EntryApi get entries;
|
|
}
|
|
|
|
/// Manipulates [Item] data.
|
|
abstract class ItemApi {
|
|
Future<Item> delete(String id);
|
|
Future<Item> get(String id);
|
|
Future<Item> insert(Item item);
|
|
Future<List<Item>> list();
|
|
Future<Item> update(Item item, String id);
|
|
Stream<List<Item>> allItemsStream();
|
|
}
|
|
|
|
/// Something being tracked.
|
|
class Item {
|
|
final String name;
|
|
String id;
|
|
|
|
Item(this.name);
|
|
}
|
|
|
|
/// Manipulates [Entry] data.
|
|
abstract class EntryApi {
|
|
Future<Entry> delete(String itemId, String id);
|
|
Future<Entry> insert(String itemId, Entry entry);
|
|
Future<List<Entry>> list(String itemId);
|
|
Future<Entry> update(String itemId, String id, Entry entry);
|
|
Stream<List<Entry>> allEntriesStream(String itemId);
|
|
}
|
|
|
|
/// A number tracked at a point in time.
|
|
class Entry {
|
|
final int value;
|
|
final DateTime time;
|
|
String id;
|
|
|
|
Entry(this.value, this.time);
|
|
}
|