Skip to content

Commit

Permalink
Requested changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkaera committed Jul 26, 2022
1 parent b3c3bcc commit c373f59
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 28 deletions.
16 changes: 8 additions & 8 deletions example/lib/database.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class TasksWidgetState extends State<TasksWidget> {
actions: <Widget>[
PopupMenuButton<int>(
itemBuilder: (context) {
return List.generate(4, (index) {
return List.generate(TaskType.values.length + 1, (index) {
return PopupMenuItem<int>(
value: index,
child: Text(
Expand Down Expand Up @@ -167,8 +167,8 @@ class TaskListCell extends StatelessWidget {
direction: DismissDirection.horizontal,
child: ListTile(
title: Text(task.message),
trailing: Text(task.timestamp.toIso8601String()),
subtitle: Text('Status: ${task.type.title}'),
trailing: Text(task.timestamp.toIso8601String()),
),
confirmDismiss: (direction) async {
String? statusMessage;
Expand All @@ -180,7 +180,7 @@ class TaskListCell extends StatelessWidget {
case DismissDirection.startToEnd:
final tasksLength = TaskType.values.length;
final nextIndex = (tasksLength + task.type.index + 1) % tasksLength;
final taskCopy = task.copy(type: TaskType.values[nextIndex]);
final taskCopy = task.copyWith(type: TaskType.values[nextIndex]);
await dao.updateTask(taskCopy);
statusMessage = 'Updated task status by: ${taskCopy.type.title}';
break;
Expand Down Expand Up @@ -251,7 +251,7 @@ class TasksTextField extends StatelessWidget {
if (message.trim().isEmpty) {
_textEditingController.clear();
} else {
final task = Task(null, false, message, DateTime.now(), TaskType.open);
final task = Task.optional(message: message);
await dao.insertTask(task);
_textEditingController.clear();
}
Expand Down
19 changes: 17 additions & 2 deletions example/lib/task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,35 @@ class Task {

final String message;

final bool? isRead;
final bool isRead;

final DateTime timestamp;

final TaskType type;

Task(this.id, this.isRead, this.message, this.timestamp, this.type);

factory Task.optional({
int? id,
DateTime? timestamp,
String? message,
bool? isRead,
TaskType? type,
}) =>
Task(
id,
isRead ?? false,
message ?? 'empty',
timestamp ?? DateTime.now(),
type ?? TaskType.open,
);

@override
String toString() {
return 'Task{id: $id, message: $message, read: $isRead, timestamp: $timestamp, type: $type}';
}

Task copy({
Task copyWith({
int? id,
String? message,
bool? isRead,
Expand Down
18 changes: 5 additions & 13 deletions floor_generator/lib/misc/type_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:source_gen/source_gen.dart';

extension SupportedTypeChecker on DartType {
extension DartTypeChecker on DartType {
/// Whether this [DartType] is either
/// - String
/// - bool
Expand All @@ -21,21 +21,11 @@ extension SupportedTypeChecker on DartType {
_uint8ListTypeChecker,
]).isExactlyType(this);
}
}

extension EnumTypeChecker on DartType {
bool get isEnumType {
final mType = this;
return mType is InterfaceType ? mType.element.isEnum : false;
}
}
bool get isEnumType => _enumTypeChecker.isSuperTypeOf(this);

extension Uint8ListTypeChecker on DartType {
bool get isUint8List =>
getDisplayString(withNullability: false) == 'Uint8List';
}
bool get isUint8List => _uint8ListTypeChecker.isExactlyType(this);

extension StreamTypeChecker on DartType {
bool get isStream => _streamTypeChecker.isExactlyType(this);
}

Expand Down Expand Up @@ -70,3 +60,5 @@ final _doubleTypeChecker = _typeChecker(double);
final _uint8ListTypeChecker = _typeChecker(Uint8List);

final _streamTypeChecker = _typeChecker(Stream);

final _enumTypeChecker = _typeChecker(Enum);
1 change: 0 additions & 1 deletion floor_generator/lib/processor/field_processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class FieldProcessor extends Processor<Field> {
} else if (typeConverter != null) {
return typeConverter.databaseType.asSqlType();
} else {
print('DEBUG:: getClosest == null');
throw InvalidGenerationSourceError(
'Column type is not supported for $type.',
todo: 'Either make to use a supported type or supply a type converter.',
Expand Down

0 comments on commit c373f59

Please sign in to comment.