1
0
mirror of https://github.com/flutter/samples.git synced 2026-04-06 11:41:26 +00:00

Migrate web dashboard to null safety (#928)

* update dependencies

* Update to cloud_firestore 2.x.x

* run dart migrate

* Fix analyzer warnings from null safety migration

* Fix errors resulting from null safety migration

* Fix info level warnings

* run flutter format

* fix tests

* remove unused import, format
This commit is contained in:
John Ryan
2021-10-12 14:38:34 -07:00
committed by GitHub
parent 0061b0d70d
commit 4893a24625
20 changed files with 277 additions and 301 deletions

View File

@@ -5,6 +5,7 @@
import 'dart:async';
import 'dart:math';
import 'package:collection/collection.dart';
import 'package:uuid/uuid.dart' as uuid;
import 'api.dart';
@@ -30,7 +31,7 @@ class MockDashboardApi implements DashboardApi {
for (var i = 0; i < 30; i++) {
var date = monthAgo.add(Duration(days: i));
var value = Random().nextInt(6) + 1;
await entries.insert(category.id, Entry(value, date));
await entries.insert(category.id!, Entry(value, date));
}
}
}
@@ -42,20 +43,20 @@ class MockCategoryApi implements CategoryApi {
StreamController<List<Category>>.broadcast();
@override
Future<Category> delete(String id) async {
Future<Category?> delete(String id) async {
var removed = _storage.remove(id);
_emit();
return removed;
}
@override
Future<Category> get(String id) async {
Future<Category?> get(String id) async {
return _storage[id];
}
@override
Future<Category> insert(Category category) async {
var id = uuid.Uuid().v4();
var id = const uuid.Uuid().v4();
var newCategory = Category(category.name)..id = id;
_storage[id] = newCategory;
_emit();
@@ -88,14 +89,14 @@ class MockEntryApi implements EntryApi {
StreamController.broadcast();
@override
Future<Entry> delete(String categoryId, String id) async {
Future<Entry?> delete(String categoryId, String id) async {
_emit(categoryId);
return _storage.remove('$categoryId-$id');
}
@override
Future<Entry> insert(String categoryId, Entry entry) async {
var id = uuid.Uuid().v4();
var id = const uuid.Uuid().v4();
var newEntry = Entry(entry.value, entry.time)..id = id;
_storage['$categoryId-$id'] = newEntry;
_emit(categoryId);
@@ -104,10 +105,12 @@ class MockEntryApi implements EntryApi {
@override
Future<List<Entry>> list(String categoryId) async {
return _storage.keys
var list = _storage.keys
.where((k) => k.startsWith(categoryId))
.map((k) => _storage[k])
.whereNotNull()
.toList();
return list;
}
@override
@@ -127,14 +130,14 @@ class MockEntryApi implements EntryApi {
void _emit(String categoryId) {
var entries = _storage.keys
.where((k) => k.startsWith(categoryId))
.map((k) => _storage[k])
.map((k) => _storage[k]!)
.toList();
_streamController.add(_EntriesEvent(categoryId, entries));
}
@override
Future<Entry> get(String categoryId, String id) async {
Future<Entry?> get(String categoryId, String id) async {
return _storage['$categoryId-$id'];
}
}