From: Hamatoma Date: Sun, 30 Jan 2022 13:14:34 +0000 (+0100) Subject: Refactoring: removing warnings X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=ccb9d71fac8b9ba8fe721b3f47902b9f5feeefdf;p=exhibition.git Refactoring: removing warnings * Refactoring: ** using const for constructors ** avoiding this for class members ** fix: avoiding "orElse: null" ** in constructor parameter list: using { ... this.attribute = default } ** avoiding "var variable;" ** preferring const instead of final --- diff --git a/lib/base/helper.dart b/lib/base/helper.dart index 7ae09be..f5f69a2 100644 --- a/lib/base/helper.dart +++ b/lib/base/helper.dart @@ -80,7 +80,7 @@ String asString(dynamic object, String dbValueToString(dynamic value, DataType dataType) { String rc; - if (!(value is String)) { + if (value is! String) { rc = asString(value); } else { switch (dataType) { @@ -191,7 +191,7 @@ dynamic jsonToObject(dynamic value, {required DataType dataType, dynamic defaultValue, bool nullReturnsNull = false}) { - var rc; + dynamic rc; if (value == null) { rc = nullReturnsNull ? null : defaultValue; } else if (value is String) { diff --git a/lib/base/i18n.dart b/lib/base/i18n.dart index 503b9d9..8694b93 100644 --- a/lib/base/i18n.dart +++ b/lib/base/i18n.dart @@ -14,17 +14,13 @@ class I18N { final regExpTag = RegExp(r'<#\d+>$'); factory I18N() { - if (instance == null) { - instance = I18N.internal(MemoryLogger()); - } + instance ??= I18N.internal(MemoryLogger()); return instance!; } - /** - * Constructor for initializing the global instance. - * - * @param logger: the logger used for error messages. - */ + /// Constructor for initializing the global instance. + /// + /// @param logger: the logger used for error messages. I18N.internal(this.logger) { instance = this; } diff --git a/lib/meta/module_meta_data.dart b/lib/meta/module_meta_data.dart index 80f924b..397d768 100644 --- a/lib/meta/module_meta_data.dart +++ b/lib/meta/module_meta_data.dart @@ -157,7 +157,7 @@ class ModuleMetaData { /// The related database table. String tableName = ''; - final needsSqlAll; + final bool needsSqlAll; /// If true the fields create, createdBy ... have the same ("short") column name /// instead of prefix and name. @@ -168,12 +168,11 @@ class ModuleMetaData { String columnPrefix = ''; ModuleMetaData(this.moduleName, this.propertyList, this.pageList, {String tableName = '', - String moduleNameSingular = '', + this.moduleNameSingular = '', String columnPrefix = '', bool shortModifiedLabel = false, - bool this.needsSqlAll = false}) { + this.needsSqlAll = false}) { this.tableName = tableName.isEmpty ? moduleName.toLowerCase() : tableName; - this.shortModifiedLabel = shortModifiedLabel; if (moduleNameSingular.isEmpty) { if (!moduleName.endsWith('s')) { moduleNameSingular = moduleName; @@ -182,10 +181,9 @@ class ModuleMetaData { moduleNameSingular = moduleName.substring(0, length); } } - this.moduleNameSingular = moduleNameSingular; this.columnPrefix = columnPrefix.isNotEmpty ? columnPrefix - : this.moduleNameSingular.toLowerCase(); + : moduleNameSingular.toLowerCase(); for (var item in propertyList) { item.module = this; @@ -228,7 +226,7 @@ class ModuleMetaData { rc = 'String'; break; case DataType.undefined: - throw FormatException('dartType(): data type is undefined'); + throw const FormatException('dartType(): data type is undefined'); } return rc; } @@ -294,7 +292,7 @@ class ModuleMetaData { } break; case DataType.undefined: - throw FormatException('mySqlType(): data type is undefined'); + throw const FormatException('mySqlType(): data type is undefined'); } return rc; } @@ -303,7 +301,7 @@ class ModuleMetaData { /// /// Override it if needed. void onInitialized() { - for (var page in this.pageList) { + for (var page in pageList) { page.onInitialized(); } } @@ -358,8 +356,13 @@ class ModuleMetaData { /// Returns the meta data of a property given by its [name] or null if missing. PropertyMetaData? propertyByName(String name) { - final rc = propertyList.singleWhere((element) => element.name == name, - orElse: null); + PropertyMetaData? rc; + for (final element in propertyList){ + if (element.name == name){ + rc = element; + break; + } + } return rc; } @@ -381,11 +384,10 @@ class PageMetaData { final List fields; final String globalComboBoxes; PageMetaData(this.label, this.pageType, - {String name = '', required this.fields, this.globalComboBoxes = ''}) { + {this.name = '', required this.fields, this.globalComboBoxes = ''}) { if (name.isEmpty) { name = enumToString(pageType); } - this.name = name; } /// Does things when the instance is inititialized. diff --git a/lib/meta/modules.dart b/lib/meta/modules.dart index ea69a72..bc1a2f0 100644 --- a/lib/meta/modules.dart +++ b/lib/meta/modules.dart @@ -35,7 +35,7 @@ ModuleMetaData? moduleByName(String name) { return rc; } /// Returns the module names as string list. -List moduleNames() { +List moduleNames(){ return [ 'Benchmarks', 'Roles', diff --git a/lib/page/benchmarks/benchmark_data.dart b/lib/page/benchmarks/benchmark_data.dart index 9f44af6..012564d 100644 --- a/lib/page/benchmarks/benchmark_data.dart +++ b/lib/page/benchmarks/benchmark_data.dart @@ -2,7 +2,7 @@ import '../../base/defines.dart'; import '../../base/helper.dart'; import '../../persistence/data_record.dart'; -class BenchmarkData extends DataRecord { +class BenchmarkData extends DataRecord{ int? id; String? lastName; String? firstName; @@ -15,116 +15,75 @@ class BenchmarkData extends DataRecord { String? createdBy; DateTime? changedAt; String? changedBy; - - BenchmarkData( - {this.id, - this.lastName, - this.firstName, - this.email, - this.birthday, - this.active, - this.weight, - this.income, - this.createdAt, - this.createdBy, - this.changedAt, - this.changedBy}); - + BenchmarkData({ + this.id, this.lastName, this.firstName, this.email, this.birthday, this.active, this.weight, this.income, this.createdAt, this.createdBy, this.changedAt, this.changedBy}); BenchmarkData.createFromMap(DataMap map) { fromMap(map); } - @override void fromMap(DataMap map) { - id = map.containsKey('benchmark_id') - ? fromString(map['benchmark_id'], dataType: DataType.reference) - : null; - lastName = map.containsKey('benchmark_lastname') - ? fromString(map['benchmark_lastname'], dataType: DataType.string) - : null; - firstName = map.containsKey('benchmark_firstname') - ? fromString(map['benchmark_firstname'], dataType: DataType.string) - : null; - email = map.containsKey('benchmark_email') - ? fromString(map['benchmark_email'], dataType: DataType.string) - : null; - birthday = map.containsKey('benchmark_birthday') - ? fromString(map['benchmark_birthday'], dataType: DataType.date) - : null; - active = map.containsKey('benchmark_active') - ? fromString(map['benchmark_active'], dataType: DataType.bool) - : null; - weight = map.containsKey('benchmark_weight') - ? fromString(map['benchmark_weight'], dataType: DataType.float) - : null; - income = map.containsKey('benchmark_income') - ? fromString(map['benchmark_income'], dataType: DataType.currency) - : null; - createdAt = map.containsKey('benchmark_createdat') - ? fromString(map['benchmark_createdat'], dataType: DataType.datetime) - : null; - createdBy = map.containsKey('benchmark_createdby') - ? fromString(map['benchmark_createdby'], dataType: DataType.string) - : null; - changedAt = map.containsKey('benchmark_changedat') - ? fromString(map['benchmark_changedat'], dataType: DataType.datetime) - : null; - changedBy = map.containsKey('benchmark_changedby') - ? fromString(map['benchmark_changedby'], dataType: DataType.string) - : null; + id = map.containsKey('benchmark_id') ? fromString(map['benchmark_id'], dataType: DataType.reference) : null; + lastName = map.containsKey('benchmark_lastname') ? fromString(map['benchmark_lastname'], dataType: DataType.string) : null; + firstName = map.containsKey('benchmark_firstname') ? fromString(map['benchmark_firstname'], dataType: DataType.string) : null; + email = map.containsKey('benchmark_email') ? fromString(map['benchmark_email'], dataType: DataType.string) : null; + birthday = map.containsKey('benchmark_birthday') ? fromString(map['benchmark_birthday'], dataType: DataType.date) : null; + active = map.containsKey('benchmark_active') ? fromString(map['benchmark_active'], dataType: DataType.bool) : null; + weight = map.containsKey('benchmark_weight') ? fromString(map['benchmark_weight'], dataType: DataType.float) : null; + income = map.containsKey('benchmark_income') ? fromString(map['benchmark_income'], dataType: DataType.currency) : null; + createdAt = map.containsKey('benchmark_createdat') ? fromString(map['benchmark_createdat'], dataType: DataType.datetime) : null; + createdBy = map.containsKey('benchmark_createdby') ? fromString(map['benchmark_createdby'], dataType: DataType.string) : null; + changedAt = map.containsKey('benchmark_changedat') ? fromString(map['benchmark_changedat'], dataType: DataType.datetime) : null; + changedBy = map.containsKey('benchmark_changedby') ? fromString(map['benchmark_changedby'], dataType: DataType.string) : null; } - @override int keyOf() { return id ?? 0; } - @override - String nameOfKey() { + String nameOfKey(){ return 'benchmark_id'; } - static DataType? dataTypeOf(String name) { DataType? rc; - switch (name) { - case 'id': - rc = DataType.reference; - break; - case 'lastName': - rc = DataType.string; - break; - case 'firstName': - rc = DataType.string; - break; - case 'email': - rc = DataType.string; - break; - case 'birthday': - rc = DataType.date; - break; - case 'active': - rc = DataType.bool; - break; - case 'weight': - rc = DataType.float; - break; - case 'income': - rc = DataType.currency; - break; - case 'createdAt': - rc = DataType.datetime; - break; - case 'createdBy': - rc = DataType.string; - break; - case 'changedAt': - rc = DataType.datetime; - break; - case 'changedBy': - rc = DataType.string; - break; - default: - break; + switch(name){ + case 'id': + rc = DataType.reference; + break; + case 'lastName': + rc = DataType.string; + break; + case 'firstName': + rc = DataType.string; + break; + case 'email': + rc = DataType.string; + break; + case 'birthday': + rc = DataType.date; + break; + case 'active': + rc = DataType.bool; + break; + case 'weight': + rc = DataType.float; + break; + case 'income': + rc = DataType.currency; + break; + case 'createdAt': + rc = DataType.datetime; + break; + case 'createdBy': + rc = DataType.string; + break; + case 'changedAt': + rc = DataType.datetime; + break; + case 'changedBy': + rc = DataType.string; + break; + default: + break; } return rc; } diff --git a/lib/page/benchmarks/create_benchmark_page.dart b/lib/page/benchmarks/create_benchmark_page.dart index a0ebe41..991604e 100644 --- a/lib/page/benchmarks/create_benchmark_page.dart +++ b/lib/page/benchmarks/create_benchmark_page.dart @@ -27,8 +27,7 @@ class CreateBenchmarkPage extends StatefulWidget { } class _CreateBenchmarkPageState extends CreateBenchmarkCustom { - _CreateBenchmarkPageState() : super(); - + _CreateBenchmarkPageState(): super(); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/benchmarks/delete_benchmark_page.dart b/lib/page/benchmarks/delete_benchmark_page.dart index a016da0..1fbb33c 100644 --- a/lib/page/benchmarks/delete_benchmark_page.dart +++ b/lib/page/benchmarks/delete_benchmark_page.dart @@ -28,8 +28,7 @@ class DeleteBenchmarkPage extends StatefulWidget { } class _DeleteBenchmarkPageState extends DeleteBenchmarkCustom { - _DeleteBenchmarkPageState(int primaryKey) : super(primaryKey); - + _DeleteBenchmarkPageState(int primaryKey): super(primaryKey); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/benchmarks/edit_benchmark_page.dart b/lib/page/benchmarks/edit_benchmark_page.dart index ccc3c99..e58ba43 100644 --- a/lib/page/benchmarks/edit_benchmark_page.dart +++ b/lib/page/benchmarks/edit_benchmark_page.dart @@ -28,8 +28,7 @@ class EditBenchmarkPage extends StatefulWidget { } class _EditBenchmarkPageState extends EditBenchmarkCustom { - _EditBenchmarkPageState(int primaryKey) : super(primaryKey); - + _EditBenchmarkPageState(int primaryKey): super(primaryKey); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/benchmarks/list_benchmark_page.dart b/lib/page/benchmarks/list_benchmark_page.dart index 9074c61..e3322eb 100644 --- a/lib/page/benchmarks/list_benchmark_page.dart +++ b/lib/page/benchmarks/list_benchmark_page.dart @@ -27,8 +27,7 @@ class ListBenchmarkPage extends StatefulWidget { } class _ListBenchmarkPageState extends ListBenchmarkCustom { - _ListBenchmarkPageState() : super(); - + _ListBenchmarkPageState(): super(); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/roles/create_role_page.dart b/lib/page/roles/create_role_page.dart index 237ab52..b9d78ae 100644 --- a/lib/page/roles/create_role_page.dart +++ b/lib/page/roles/create_role_page.dart @@ -27,8 +27,7 @@ class CreateRolePage extends StatefulWidget { } class _CreateRolePageState extends CreateRoleCustom { - _CreateRolePageState() : super(); - + _CreateRolePageState(): super(); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/roles/edit_role_page.dart b/lib/page/roles/edit_role_page.dart index b2abd65..783f22a 100644 --- a/lib/page/roles/edit_role_page.dart +++ b/lib/page/roles/edit_role_page.dart @@ -28,8 +28,7 @@ class EditRolePage extends StatefulWidget { } class _EditRolePageState extends EditRoleCustom { - _EditRolePageState(int primaryKey) : super(primaryKey); - + _EditRolePageState(int primaryKey): super(primaryKey); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/roles/list_role_page.dart b/lib/page/roles/list_role_page.dart index 491a3c1..5ca9b46 100644 --- a/lib/page/roles/list_role_page.dart +++ b/lib/page/roles/list_role_page.dart @@ -27,8 +27,7 @@ class ListRolePage extends StatefulWidget { } class _ListRolePageState extends ListRoleCustom { - _ListRolePageState() : super(); - + _ListRolePageState(): super(); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/roles/role_data.dart b/lib/page/roles/role_data.dart index bd2c7ae..0b1a3ca 100644 --- a/lib/page/roles/role_data.dart +++ b/lib/page/roles/role_data.dart @@ -2,81 +2,58 @@ import '../../base/defines.dart'; import '../../base/helper.dart'; import '../../persistence/data_record.dart'; -class RoleData extends DataRecord { +class RoleData extends DataRecord{ int? id; String? name; DateTime? createdAt; String? createdBy; DateTime? changedAt; String? changedBy; - - RoleData( - {this.id, - this.name, - this.createdAt, - this.createdBy, - this.changedAt, - this.changedBy}); - + RoleData({ + this.id, this.name, this.createdAt, this.createdBy, this.changedAt, this.changedBy}); RoleData.createFromMap(DataMap map) { fromMap(map); } - @override void fromMap(DataMap map) { - id = map.containsKey('role_id') - ? fromString(map['role_id'], dataType: DataType.reference) - : null; - name = map.containsKey('role_name') - ? fromString(map['role_name'], dataType: DataType.string) - : null; - createdAt = map.containsKey('role_createdat') - ? fromString(map['role_createdat'], dataType: DataType.datetime) - : null; - createdBy = map.containsKey('role_createdby') - ? fromString(map['role_createdby'], dataType: DataType.string) - : null; - changedAt = map.containsKey('role_changedat') - ? fromString(map['role_changedat'], dataType: DataType.datetime) - : null; - changedBy = map.containsKey('role_changedby') - ? fromString(map['role_changedby'], dataType: DataType.string) - : null; + id = map.containsKey('role_id') ? fromString(map['role_id'], dataType: DataType.reference) : null; + name = map.containsKey('role_name') ? fromString(map['role_name'], dataType: DataType.string) : null; + createdAt = map.containsKey('role_createdat') ? fromString(map['role_createdat'], dataType: DataType.datetime) : null; + createdBy = map.containsKey('role_createdby') ? fromString(map['role_createdby'], dataType: DataType.string) : null; + changedAt = map.containsKey('role_changedat') ? fromString(map['role_changedat'], dataType: DataType.datetime) : null; + changedBy = map.containsKey('role_changedby') ? fromString(map['role_changedby'], dataType: DataType.string) : null; } - @override int keyOf() { return id ?? 0; } - @override - String nameOfKey() { + String nameOfKey(){ return 'role_id'; } - static DataType? dataTypeOf(String name) { DataType? rc; - switch (name) { - case 'id': - rc = DataType.reference; - break; - case 'name': - rc = DataType.string; - break; - case 'createdAt': - rc = DataType.datetime; - break; - case 'createdBy': - rc = DataType.string; - break; - case 'changedAt': - rc = DataType.datetime; - break; - case 'changedBy': - rc = DataType.string; - break; - default: - break; + switch(name){ + case 'id': + rc = DataType.reference; + break; + case 'name': + rc = DataType.string; + break; + case 'createdAt': + rc = DataType.datetime; + break; + case 'createdBy': + rc = DataType.string; + break; + case 'changedAt': + rc = DataType.datetime; + break; + case 'changedBy': + rc = DataType.string; + break; + default: + break; } return rc; } diff --git a/lib/page/rolestarter/list_rolestarter_page.dart b/lib/page/rolestarter/list_rolestarter_page.dart index 8e218ca..a8dc117 100644 --- a/lib/page/rolestarter/list_rolestarter_page.dart +++ b/lib/page/rolestarter/list_rolestarter_page.dart @@ -27,8 +27,7 @@ class ListRoleStarterPage extends StatefulWidget { } class _ListRoleStarterPageState extends ListRoleStarterCustom { - _ListRoleStarterPageState() : super(); - + _ListRoleStarterPageState(): super(); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/rolestarter/mapping_rolestarter_page.dart b/lib/page/rolestarter/mapping_rolestarter_page.dart index 3db5408..a49f2bf 100644 --- a/lib/page/rolestarter/mapping_rolestarter_page.dart +++ b/lib/page/rolestarter/mapping_rolestarter_page.dart @@ -27,8 +27,7 @@ class MappingRoleStarterPage extends StatefulWidget { } class _MappingRoleStarterPageState extends MappingRoleStarterCustom { - _MappingRoleStarterPageState() : super(); - + _MappingRoleStarterPageState(): super(); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/rolestarter/role_starter_data.dart b/lib/page/rolestarter/role_starter_data.dart index 682fca3..cfec0fa 100644 --- a/lib/page/rolestarter/role_starter_data.dart +++ b/lib/page/rolestarter/role_starter_data.dart @@ -2,7 +2,7 @@ import '../../base/defines.dart'; import '../../base/helper.dart'; import '../../persistence/data_record.dart'; -class RoleStarterData extends DataRecord { +class RoleStarterData extends DataRecord{ int? id; int? role; int? starter; @@ -11,88 +11,59 @@ class RoleStarterData extends DataRecord { String? createdBy; DateTime? changedAt; String? changedBy; - - RoleStarterData( - {this.id, - this.role, - this.starter, - this.order, - this.createdAt, - this.createdBy, - this.changedAt, - this.changedBy}); - + RoleStarterData({ + this.id, this.role, this.starter, this.order, this.createdAt, this.createdBy, this.changedAt, this.changedBy}); RoleStarterData.createFromMap(DataMap map) { fromMap(map); } - @override void fromMap(DataMap map) { - id = map.containsKey('rolestarter_id') - ? fromString(map['rolestarter_id'], dataType: DataType.reference) - : null; - role = map.containsKey('rolestarter_role') - ? fromString(map['rolestarter_role'], dataType: DataType.reference) - : null; - starter = map.containsKey('rolestarter_starter') - ? fromString(map['rolestarter_starter'], dataType: DataType.reference) - : null; - order = map.containsKey('rolestarter_order') - ? fromString(map['rolestarter_order'], dataType: DataType.int) - : null; - createdAt = map.containsKey('rolestarter_createdat') - ? fromString(map['rolestarter_createdat'], dataType: DataType.datetime) - : null; - createdBy = map.containsKey('rolestarter_createdby') - ? fromString(map['rolestarter_createdby'], dataType: DataType.string) - : null; - changedAt = map.containsKey('rolestarter_changedat') - ? fromString(map['rolestarter_changedat'], dataType: DataType.datetime) - : null; - changedBy = map.containsKey('rolestarter_changedby') - ? fromString(map['rolestarter_changedby'], dataType: DataType.string) - : null; + id = map.containsKey('rolestarter_id') ? fromString(map['rolestarter_id'], dataType: DataType.reference) : null; + role = map.containsKey('rolestarter_role') ? fromString(map['rolestarter_role'], dataType: DataType.reference) : null; + starter = map.containsKey('rolestarter_starter') ? fromString(map['rolestarter_starter'], dataType: DataType.reference) : null; + order = map.containsKey('rolestarter_order') ? fromString(map['rolestarter_order'], dataType: DataType.int) : null; + createdAt = map.containsKey('rolestarter_createdat') ? fromString(map['rolestarter_createdat'], dataType: DataType.datetime) : null; + createdBy = map.containsKey('rolestarter_createdby') ? fromString(map['rolestarter_createdby'], dataType: DataType.string) : null; + changedAt = map.containsKey('rolestarter_changedat') ? fromString(map['rolestarter_changedat'], dataType: DataType.datetime) : null; + changedBy = map.containsKey('rolestarter_changedby') ? fromString(map['rolestarter_changedby'], dataType: DataType.string) : null; } - @override int keyOf() { return id ?? 0; } - @override - String nameOfKey() { + String nameOfKey(){ return 'rolestarter_id'; } - static DataType? dataTypeOf(String name) { DataType? rc; - switch (name) { - case 'id': - rc = DataType.reference; - break; - case 'role': - rc = DataType.reference; - break; - case 'starter': - rc = DataType.reference; - break; - case 'order': - rc = DataType.int; - break; - case 'createdAt': - rc = DataType.datetime; - break; - case 'createdBy': - rc = DataType.string; - break; - case 'changedAt': - rc = DataType.datetime; - break; - case 'changedBy': - rc = DataType.string; - break; - default: - break; + switch(name){ + case 'id': + rc = DataType.reference; + break; + case 'role': + rc = DataType.reference; + break; + case 'starter': + rc = DataType.reference; + break; + case 'order': + rc = DataType.int; + break; + case 'createdAt': + rc = DataType.datetime; + break; + case 'createdBy': + rc = DataType.string; + break; + case 'changedAt': + rc = DataType.datetime; + break; + case 'changedBy': + rc = DataType.string; + break; + default: + break; } return rc; } diff --git a/lib/page/scopes/create_scope_page.dart b/lib/page/scopes/create_scope_page.dart index 790dcda..89e3a03 100644 --- a/lib/page/scopes/create_scope_page.dart +++ b/lib/page/scopes/create_scope_page.dart @@ -8,9 +8,7 @@ import 'create_scope_custom.dart'; class CreateScopePage extends StatefulWidget { final PageStates pageStates = PageStates(); - CreateScopePage() : super(); - @override _CreateScopePageState createState() { final rc = _CreateScopePageState(); @@ -29,8 +27,7 @@ class CreateScopePage extends StatefulWidget { } class _CreateScopePageState extends CreateScopeCustom { - _CreateScopePageState() : super(); - + _CreateScopePageState(): super(); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/scopes/delete_scope_page.dart b/lib/page/scopes/delete_scope_page.dart index d49cad1..9a77550 100644 --- a/lib/page/scopes/delete_scope_page.dart +++ b/lib/page/scopes/delete_scope_page.dart @@ -9,9 +9,7 @@ import 'delete_scope_custom.dart'; class DeleteScopePage extends StatefulWidget { final int primaryKey; final PageStates pageStates = PageStates(); - DeleteScopePage(this.primaryKey) : super(); - @override _DeleteScopePageState createState() { final rc = _DeleteScopePageState(this.primaryKey); @@ -30,8 +28,7 @@ class DeleteScopePage extends StatefulWidget { } class _DeleteScopePageState extends DeleteScopeCustom { - _DeleteScopePageState(int primaryKey) : super(primaryKey); - + _DeleteScopePageState(int primaryKey): super(primaryKey); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/scopes/edit_scope_page.dart b/lib/page/scopes/edit_scope_page.dart index a6c80d5..74be668 100644 --- a/lib/page/scopes/edit_scope_page.dart +++ b/lib/page/scopes/edit_scope_page.dart @@ -9,9 +9,7 @@ import 'edit_scope_custom.dart'; class EditScopePage extends StatefulWidget { final int primaryKey; final PageStates pageStates = PageStates(); - EditScopePage(this.primaryKey) : super(); - @override _EditScopePageState createState() { final rc = _EditScopePageState(this.primaryKey); @@ -30,8 +28,7 @@ class EditScopePage extends StatefulWidget { } class _EditScopePageState extends EditScopeCustom { - _EditScopePageState(int primaryKey) : super(primaryKey); - + _EditScopePageState(int primaryKey): super(primaryKey); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/scopes/list_scope_page.dart b/lib/page/scopes/list_scope_page.dart index 0c5c506..3ccb9ef 100644 --- a/lib/page/scopes/list_scope_page.dart +++ b/lib/page/scopes/list_scope_page.dart @@ -8,9 +8,7 @@ import 'list_scope_custom.dart'; class ListScopePage extends StatefulWidget { final PageStates pageStates = PageStates(); - ListScopePage() : super(); - @override _ListScopePageState createState() { final rc = _ListScopePageState(); @@ -29,8 +27,7 @@ class ListScopePage extends StatefulWidget { } class _ListScopePageState extends ListScopeCustom { - _ListScopePageState() : super(); - + _ListScopePageState(): super(); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/scopes/scope_data.dart b/lib/page/scopes/scope_data.dart index 64fa61b..582183d 100644 --- a/lib/page/scopes/scope_data.dart +++ b/lib/page/scopes/scope_data.dart @@ -2,8 +2,7 @@ import '../../base/defines.dart'; import '../../base/helper.dart'; import '../../persistence/data_record.dart'; - -class ScopeData extends DataRecord { +class ScopeData extends DataRecord{ int? id; String? scope; String? name; @@ -13,99 +12,66 @@ class ScopeData extends DataRecord { String? createdBy; DateTime? changedAt; String? changedBy; - - ScopeData( - {this.id, - this.scope, - this.name, - this.value, - this.position, - this.createdAt, - this.createdBy, - this.changedAt, - this.changedBy}); - + ScopeData({ + this.id, this.scope, this.name, this.value, this.position, this.createdAt, this.createdBy, this.changedAt, this.changedBy}); ScopeData.createFromMap(DataMap map) { fromMap(map); } - @override void fromMap(DataMap map) { - id = map.containsKey('scope_id') - ? fromString(map['scope_id'], dataType: DataType.reference) - : null; - scope = map.containsKey('scope_scope') - ? fromString(map['scope_scope'], dataType: DataType.string) - : null; - name = map.containsKey('scope_name') - ? fromString(map['scope_name'], dataType: DataType.string) - : null; - value = map.containsKey('scope_value') - ? fromString(map['scope_value'], dataType: DataType.string) - : null; - position = map.containsKey('scope_position') - ? fromString(map['scope_position'], dataType: DataType.int) - : null; - createdAt = map.containsKey('scope_createdat') - ? fromString(map['scope_createdat'], dataType: DataType.datetime) - : null; - createdBy = map.containsKey('scope_createdby') - ? fromString(map['scope_createdby'], dataType: DataType.string) - : null; - changedAt = map.containsKey('scope_changedat') - ? fromString(map['scope_changedat'], dataType: DataType.datetime) - : null; - changedBy = map.containsKey('scope_changedby') - ? fromString(map['scope_changedby'], dataType: DataType.string) - : null; + id = map.containsKey('scope_id') ? fromString(map['scope_id'], dataType: DataType.reference) : null; + scope = map.containsKey('scope_scope') ? fromString(map['scope_scope'], dataType: DataType.string) : null; + name = map.containsKey('scope_name') ? fromString(map['scope_name'], dataType: DataType.string) : null; + value = map.containsKey('scope_value') ? fromString(map['scope_value'], dataType: DataType.string) : null; + position = map.containsKey('scope_position') ? fromString(map['scope_position'], dataType: DataType.int) : null; + createdAt = map.containsKey('scope_createdat') ? fromString(map['scope_createdat'], dataType: DataType.datetime) : null; + createdBy = map.containsKey('scope_createdby') ? fromString(map['scope_createdby'], dataType: DataType.string) : null; + changedAt = map.containsKey('scope_changedat') ? fromString(map['scope_changedat'], dataType: DataType.datetime) : null; + changedBy = map.containsKey('scope_changedby') ? fromString(map['scope_changedby'], dataType: DataType.string) : null; } - @override int keyOf() { return id ?? 0; } - @override - String nameOfKey() { + String nameOfKey(){ return 'scope_id'; } - static DataType? dataTypeOf(String name) { DataType? rc; - switch (name) { - case 'id': - rc = DataType.reference; - break; - case 'scope': - rc = DataType.string; - break; - case 'name': - rc = DataType.string; - break; - case 'value': - rc = DataType.string; - break; - case 'position': - rc = DataType.int; - break; - case 'createdAt': - rc = DataType.datetime; - break; - case 'createdBy': - rc = DataType.string; - break; - case 'changedAt': - rc = DataType.datetime; - break; - case 'changedBy': - rc = DataType.string; - break; - default: - break; + switch(name){ + case 'id': + rc = DataType.reference; + break; + case 'scope': + rc = DataType.string; + break; + case 'name': + rc = DataType.string; + break; + case 'value': + rc = DataType.string; + break; + case 'position': + rc = DataType.int; + break; + case 'createdAt': + rc = DataType.datetime; + break; + case 'createdBy': + rc = DataType.string; + break; + case 'changedAt': + rc = DataType.datetime; + break; + case 'changedBy': + rc = DataType.string; + break; + default: + break; } return rc; } - @override DataMap toMap({DataMap? map, bool clear = true}) { map ??= DataMap(); diff --git a/lib/page/starters/create_starter_page.dart b/lib/page/starters/create_starter_page.dart index f32e54e..7e3c775 100644 --- a/lib/page/starters/create_starter_page.dart +++ b/lib/page/starters/create_starter_page.dart @@ -27,8 +27,7 @@ class CreateStarterPage extends StatefulWidget { } class _CreateStarterPageState extends CreateStarterCustom { - _CreateStarterPageState() : super(); - + _CreateStarterPageState(): super(); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/starters/delete_starter_page.dart b/lib/page/starters/delete_starter_page.dart index 9a944ed..c005795 100644 --- a/lib/page/starters/delete_starter_page.dart +++ b/lib/page/starters/delete_starter_page.dart @@ -28,8 +28,7 @@ class DeleteStarterPage extends StatefulWidget { } class _DeleteStarterPageState extends DeleteStarterCustom { - _DeleteStarterPageState(int primaryKey) : super(primaryKey); - + _DeleteStarterPageState(int primaryKey): super(primaryKey); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/starters/edit_starter_page.dart b/lib/page/starters/edit_starter_page.dart index 553d8dd..4c835d8 100644 --- a/lib/page/starters/edit_starter_page.dart +++ b/lib/page/starters/edit_starter_page.dart @@ -28,8 +28,7 @@ class EditStarterPage extends StatefulWidget { } class _EditStarterPageState extends EditStarterCustom { - _EditStarterPageState(int primaryKey) : super(primaryKey); - + _EditStarterPageState(int primaryKey): super(primaryKey); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/starters/list_starter_page.dart b/lib/page/starters/list_starter_page.dart index 974a2e3..11bfb00 100644 --- a/lib/page/starters/list_starter_page.dart +++ b/lib/page/starters/list_starter_page.dart @@ -27,8 +27,7 @@ class ListStarterPage extends StatefulWidget { } class _ListStarterPageState extends ListStarterCustom { - _ListStarterPageState() : super(); - + _ListStarterPageState(): super(); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/starters/starter_data.dart b/lib/page/starters/starter_data.dart index 37bffc1..40b89c8 100644 --- a/lib/page/starters/starter_data.dart +++ b/lib/page/starters/starter_data.dart @@ -2,7 +2,7 @@ import '../../base/defines.dart'; import '../../base/helper.dart'; import '../../persistence/data_record.dart'; -class StarterData extends DataRecord { +class StarterData extends DataRecord{ int? id; String? name; String? route; @@ -11,88 +11,59 @@ class StarterData extends DataRecord { String? createdBy; DateTime? changedAt; String? changedBy; - - StarterData( - {this.id, - this.name, - this.route, - this.icon, - this.createdAt, - this.createdBy, - this.changedAt, - this.changedBy}); - + StarterData({ + this.id, this.name, this.route, this.icon, this.createdAt, this.createdBy, this.changedAt, this.changedBy}); StarterData.createFromMap(DataMap map) { fromMap(map); } - @override void fromMap(DataMap map) { - id = map.containsKey('starter_id') - ? fromString(map['starter_id'], dataType: DataType.reference) - : null; - name = map.containsKey('starter_name') - ? fromString(map['starter_name'], dataType: DataType.string) - : null; - route = map.containsKey('starter_route') - ? fromString(map['starter_route'], dataType: DataType.string) - : null; - icon = map.containsKey('starter_icon') - ? fromString(map['starter_icon'], dataType: DataType.string) - : null; - createdAt = map.containsKey('starter_createdat') - ? fromString(map['starter_createdat'], dataType: DataType.datetime) - : null; - createdBy = map.containsKey('starter_createdby') - ? fromString(map['starter_createdby'], dataType: DataType.string) - : null; - changedAt = map.containsKey('starter_changedat') - ? fromString(map['starter_changedat'], dataType: DataType.datetime) - : null; - changedBy = map.containsKey('starter_changedby') - ? fromString(map['starter_changedby'], dataType: DataType.string) - : null; + id = map.containsKey('starter_id') ? fromString(map['starter_id'], dataType: DataType.reference) : null; + name = map.containsKey('starter_name') ? fromString(map['starter_name'], dataType: DataType.string) : null; + route = map.containsKey('starter_route') ? fromString(map['starter_route'], dataType: DataType.string) : null; + icon = map.containsKey('starter_icon') ? fromString(map['starter_icon'], dataType: DataType.string) : null; + createdAt = map.containsKey('starter_createdat') ? fromString(map['starter_createdat'], dataType: DataType.datetime) : null; + createdBy = map.containsKey('starter_createdby') ? fromString(map['starter_createdby'], dataType: DataType.string) : null; + changedAt = map.containsKey('starter_changedat') ? fromString(map['starter_changedat'], dataType: DataType.datetime) : null; + changedBy = map.containsKey('starter_changedby') ? fromString(map['starter_changedby'], dataType: DataType.string) : null; } - @override int keyOf() { return id ?? 0; } - @override - String nameOfKey() { + String nameOfKey(){ return 'starter_id'; } - static DataType? dataTypeOf(String name) { DataType? rc; - switch (name) { - case 'id': - rc = DataType.reference; - break; - case 'name': - rc = DataType.string; - break; - case 'route': - rc = DataType.string; - break; - case 'icon': - rc = DataType.string; - break; - case 'createdAt': - rc = DataType.datetime; - break; - case 'createdBy': - rc = DataType.string; - break; - case 'changedAt': - rc = DataType.datetime; - break; - case 'changedBy': - rc = DataType.string; - break; - default: - break; + switch(name){ + case 'id': + rc = DataType.reference; + break; + case 'name': + rc = DataType.string; + break; + case 'route': + rc = DataType.string; + break; + case 'icon': + rc = DataType.string; + break; + case 'createdAt': + rc = DataType.datetime; + break; + case 'createdBy': + rc = DataType.string; + break; + case 'changedAt': + rc = DataType.datetime; + break; + case 'changedBy': + rc = DataType.string; + break; + default: + break; } return rc; } diff --git a/lib/page/users/create_user_page.dart b/lib/page/users/create_user_page.dart index 4d6f4ad..d9753e5 100644 --- a/lib/page/users/create_user_page.dart +++ b/lib/page/users/create_user_page.dart @@ -27,8 +27,7 @@ class CreateUserPage extends StatefulWidget { } class _CreateUserPageState extends CreateUserCustom { - _CreateUserPageState() : super(); - + _CreateUserPageState(): super(); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/users/delete_user_page.dart b/lib/page/users/delete_user_page.dart index 91c7968..e47fd89 100644 --- a/lib/page/users/delete_user_page.dart +++ b/lib/page/users/delete_user_page.dart @@ -28,8 +28,7 @@ class DeleteUserPage extends StatefulWidget { } class _DeleteUserPageState extends DeleteUserCustom { - _DeleteUserPageState(int primaryKey) : super(primaryKey); - + _DeleteUserPageState(int primaryKey): super(primaryKey); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/users/edit_user_page.dart b/lib/page/users/edit_user_page.dart index 5378365..cdad6f5 100644 --- a/lib/page/users/edit_user_page.dart +++ b/lib/page/users/edit_user_page.dart @@ -28,8 +28,7 @@ class EditUserPage extends StatefulWidget { } class _EditUserPageState extends EditUserCustom { - _EditUserPageState(int primaryKey) : super(primaryKey); - + _EditUserPageState(int primaryKey): super(primaryKey); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/users/list_user_page.dart b/lib/page/users/list_user_page.dart index a83638e..ee8b21d 100644 --- a/lib/page/users/list_user_page.dart +++ b/lib/page/users/list_user_page.dart @@ -27,8 +27,7 @@ class ListUserPage extends StatefulWidget { } class _ListUserPageState extends ListUserCustom { - _ListUserPageState() : super(); - + _ListUserPageState(): super(); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/users/user_data.dart b/lib/page/users/user_data.dart index 7cac062..f4fb24f 100644 --- a/lib/page/users/user_data.dart +++ b/lib/page/users/user_data.dart @@ -2,7 +2,7 @@ import '../../base/defines.dart'; import '../../base/helper.dart'; import '../../persistence/data_record.dart'; -class UserData extends DataRecord { +class UserData extends DataRecord{ int? id; String? name; String? displayName; @@ -13,102 +13,67 @@ class UserData extends DataRecord { String? createdBy; DateTime? changedAt; String? changedBy; - - UserData( - {this.id, - this.name, - this.displayName, - this.email, - this.role, - this.status, - this.createdAt, - this.createdBy, - this.changedAt, - this.changedBy}); - + UserData({ + this.id, this.name, this.displayName, this.email, this.role, this.status, this.createdAt, this.createdBy, this.changedAt, this.changedBy}); UserData.createFromMap(DataMap map) { fromMap(map); } - @override void fromMap(DataMap map) { - id = map.containsKey('user_id') - ? fromString(map['user_id'], dataType: DataType.reference) - : null; - name = map.containsKey('user_name') - ? fromString(map['user_name'], dataType: DataType.string) - : null; - displayName = map.containsKey('user_displayname') - ? fromString(map['user_displayname'], dataType: DataType.string) - : null; - email = map.containsKey('user_email') - ? fromString(map['user_email'], dataType: DataType.string) - : null; - role = map.containsKey('user_role') - ? fromString(map['user_role'], dataType: DataType.reference) - : null; - status = map.containsKey('user_status') - ? fromString(map['user_status'], dataType: DataType.reference) - : null; - createdAt = map.containsKey('user_createdat') - ? fromString(map['user_createdat'], dataType: DataType.datetime) - : null; - createdBy = map.containsKey('user_createdby') - ? fromString(map['user_createdby'], dataType: DataType.string) - : null; - changedAt = map.containsKey('user_changedat') - ? fromString(map['user_changedat'], dataType: DataType.datetime) - : null; - changedBy = map.containsKey('user_changedby') - ? fromString(map['user_changedby'], dataType: DataType.string) - : null; + id = map.containsKey('user_id') ? fromString(map['user_id'], dataType: DataType.reference) : null; + name = map.containsKey('user_name') ? fromString(map['user_name'], dataType: DataType.string) : null; + displayName = map.containsKey('user_displayname') ? fromString(map['user_displayname'], dataType: DataType.string) : null; + email = map.containsKey('user_email') ? fromString(map['user_email'], dataType: DataType.string) : null; + role = map.containsKey('user_role') ? fromString(map['user_role'], dataType: DataType.reference) : null; + status = map.containsKey('user_status') ? fromString(map['user_status'], dataType: DataType.reference) : null; + createdAt = map.containsKey('user_createdat') ? fromString(map['user_createdat'], dataType: DataType.datetime) : null; + createdBy = map.containsKey('user_createdby') ? fromString(map['user_createdby'], dataType: DataType.string) : null; + changedAt = map.containsKey('user_changedat') ? fromString(map['user_changedat'], dataType: DataType.datetime) : null; + changedBy = map.containsKey('user_changedby') ? fromString(map['user_changedby'], dataType: DataType.string) : null; } - @override int keyOf() { return id ?? 0; } - @override - String nameOfKey() { + String nameOfKey(){ return 'user_id'; } - static DataType? dataTypeOf(String name) { DataType? rc; - switch (name) { - case 'id': - rc = DataType.reference; - break; - case 'name': - rc = DataType.string; - break; - case 'displayName': - rc = DataType.string; - break; - case 'email': - rc = DataType.string; - break; - case 'role': - rc = DataType.reference; - break; - case 'status': - rc = DataType.reference; - break; - case 'createdAt': - rc = DataType.datetime; - break; - case 'createdBy': - rc = DataType.string; - break; - case 'changedAt': - rc = DataType.datetime; - break; - case 'changedBy': - rc = DataType.string; - break; - default: - break; + switch(name){ + case 'id': + rc = DataType.reference; + break; + case 'name': + rc = DataType.string; + break; + case 'displayName': + rc = DataType.string; + break; + case 'email': + rc = DataType.string; + break; + case 'role': + rc = DataType.reference; + break; + case 'status': + rc = DataType.reference; + break; + case 'createdAt': + rc = DataType.datetime; + break; + case 'createdBy': + rc = DataType.string; + break; + case 'changedAt': + rc = DataType.datetime; + break; + case 'changedBy': + rc = DataType.string; + break; + default: + break; } return rc; } diff --git a/lib/persistence/data_table.dart b/lib/persistence/data_table.dart index 5f9f924..c959b1a 100644 --- a/lib/persistence/data_table.dart +++ b/lib/persistence/data_table.dart @@ -26,7 +26,7 @@ class DataTable { /// /// Returns the records matching the filters. If no filter is given all /// records are returned. - Iterable> recordsOf( + Iterable> recordsOf( {RecordFilter? recordFilter, KeyFilter? keyFilter}) { final keys2 = keyFilter == null ? keys : keys.where((element) => keyFilter(element)); diff --git a/lib/persistence/file_persistence.dart b/lib/persistence/file_persistence.dart index 66b6e38..c699019 100644 --- a/lib/persistence/file_persistence.dart +++ b/lib/persistence/file_persistence.dart @@ -32,11 +32,13 @@ class FilePersistence extends Persistence { @override Future query({required String what, DataMap? data}) async { - var rc; + DbData rc; final fn = path.join(dataDirectory, '$what.json'); final file = File(fn); if (!await file.exists()) { - logger.error('missing $fn'); + final message = 'missing $fn'; + logger.error(message); + rc = DbData.message(message); } else { final content = await file.readAsString(); final data = convert.jsonDecode(content); diff --git a/lib/setting/drawer_exhibition.dart b/lib/setting/drawer_exhibition.dart index d7160d7..93db7a1 100644 --- a/lib/setting/drawer_exhibition.dart +++ b/lib/setting/drawer_exhibition.dart @@ -101,6 +101,9 @@ class MenuConverter { case 'analytics_outlined': rc = Icons.analytics_outlined; break; + case 'calendar_today_outlined': + rc = Icons.calendar_today_outlined; + break; default: logger.error('MenuConverter.iconByName(): unknown icon $name'); break; diff --git a/lib/setting/footer_exhibition.dart b/lib/setting/footer_exhibition.dart index 5488cce..cfb588b 100644 --- a/lib/setting/footer_exhibition.dart +++ b/lib/setting/footer_exhibition.dart @@ -11,14 +11,14 @@ class FooterExhibition implements FooterInterface { child: const Text('Impressum'), onTap: () => launch('https://public.hamatoma.de'), ), - // SizedBox( + // const SizedBox( // width: 100, // ), InkWell( child: const Text('Datenschutz'), onTap: () => launch('https://public.hamatoma.de'), ), - // SizedBox( + // const SizedBox( // width: 150, // ), const Text('Version ${GlobalData.version}'), diff --git a/lib/setting/global_data.dart b/lib/setting/global_data.dart index 00f4031..7b78012 100644 --- a/lib/setting/global_data.dart +++ b/lib/setting/global_data.dart @@ -27,7 +27,7 @@ class GlobalData { static late GlobalData _instance; static String baseDirectory = ''; static var serverEnvironment = ServerEnvironment.productive; - static final String applicationName = theApplicationName; + static const String applicationName = theApplicationName; static String loginUserName = 'guest'; static int loginUserId = 0; static int loginUserRole = 90; @@ -76,10 +76,10 @@ class GlobalData { } class GlobalThemeData { - static final formBackgroundColor = Color.fromARGB(0xee, 0xee, 0xee, 0xee); - static final formElevation = 10.0; - static final formTextBackgroundColor = Colors.white; - static final padding = 16.0; + static const formBackgroundColor = Color.fromARGB(0xee, 0xee, 0xee, 0xee); + static const formElevation = 10.0; + static const formTextBackgroundColor = Colors.white; + static const padding = 16.0; } class GlobalTranslations { @@ -98,7 +98,7 @@ class HomeDirectories { } else if (Platform.isAndroid) { getExternalStorageDirectory().then((dir) => localData = dir!); } else { - throw FormatException('HomeDirectory.getHomePath(): unknown platform'); + throw const FormatException('HomeDirectory.getHomePath(): unknown platform'); } } } diff --git a/lib/setting/installation.dart b/lib/setting/installation.dart index f4bf2fe..5242eaa 100644 --- a/lib/setting/installation.dart +++ b/lib/setting/installation.dart @@ -149,7 +149,7 @@ class Installation { } } on FormatException catch (exc) { rc = logger - .error('${configurationFile.path}: ' + i18n.tr('failure:' + ' $exc')); + .error('${configurationFile.path}: ' + i18n.tr('failure:') + ' $exc'); } return rc; } @@ -193,7 +193,7 @@ class Installation { /// Returns the name of [permission]. static String nameOfPermission(Permission permission) { - var rc; + String rc; if (permission == Permission.storage) { rc = i18n.tr('Storage'); } else if (permission == Permission.camera) { diff --git a/lib/setting/structure.dart b/lib/setting/structure.dart index 514fb0e..b65284e 100644 --- a/lib/setting/structure.dart +++ b/lib/setting/structure.dart @@ -35,7 +35,7 @@ class Structures { /// The file named [filename] contains the items in a JSon format with /// names given by the database table structures. Structures.fromFile(String filename) { - this.globalData = GlobalData(); + globalData = GlobalData(); final file = File(filename); if (!file.existsSync()) { globalData.logger.error('cannot read structures from $filename'); diff --git a/lib/widget/attended_page.dart b/lib/widget/attended_page.dart index 638c379..5c4005b 100644 --- a/lib/widget/attended_page.dart +++ b/lib/widget/attended_page.dart @@ -61,10 +61,10 @@ class AttendedPage extends ChangeNotifier { rc.add(ComboboxAttended(item, this)); break; case DisplayType.checkbox: - throw FormatException( + throw const FormatException( 'AttendedPage.widgetOf(): not implemented: checkbox'); case DisplayType.custom: - throw FormatException( + throw const FormatException( 'AttendedPage.widgetOf(): not implemented: custom'); } } @@ -151,7 +151,7 @@ class AttendedPage extends ChangeNotifier { ); widgets.add(currentChip); if (pageCount > 7 && (ix == 0 && !inTop || ix == 7 - 2 && !inTail)) { - widgets.add(Text(' ... ')); + widgets.add(const Text(' ... ')); } } Widget? rc = Wrap(children: widgets); @@ -204,7 +204,7 @@ class AttendedPage extends ChangeNotifier { List? rc; if (dbData.recordList != null) { rc = []; - dbData.recordList!.forEach((record) { + for (var record in dbData.recordList!) { final cells = []; for (var column in columnList.split(';')) { final primaryKey = moduleMetaData.primaryOf()?.columnName; @@ -220,8 +220,8 @@ class AttendedPage extends ChangeNotifier { })); } final rc3 = DataRow(cells: cells); - rc!.add(rc3); - }); + rc.add(rc3); + } } return rc ?? []; } diff --git a/lib/widget/attended_stateful.dart b/lib/widget/attended_stateful.dart index dbadd10..c878bc8 100644 --- a/lib/widget/attended_stateful.dart +++ b/lib/widget/attended_stateful.dart @@ -3,4 +3,6 @@ import 'attended_page.dart'; abstract class AttendedStateful extends StatefulWidget { final PageStates pageStates = PageStates(); + + AttendedStateful({Key? key}) : super(key: key); } diff --git a/lib/widget/date_time_form_field.dart b/lib/widget/date_time_form_field.dart index e9fc3fb..ed23bb1 100644 --- a/lib/widget/date_time_form_field.dart +++ b/lib/widget/date_time_form_field.dart @@ -46,7 +46,7 @@ class DateTimeData { this.initialTime = initialTime; } this.initialDate = initialDate ?? now; - this.initialTime = initialTime ?? TimeOfDay(hour: 8, minute: 0); + this.initialTime = initialTime ?? const TimeOfDay(hour: 8, minute: 0); this.lastDate = lastDate ?? DateTime(now.year + 1); this.firstDate = firstDate ?? DateTime(now.year - 1); selectedDate = initialDate; @@ -57,7 +57,7 @@ class DateTimeData { {required Function(DateTime selected) storeSelected}) async { final TimeOfDay? picked = await showTimePicker( context: context, - initialTime: initialTime ?? TimeOfDay(hour: 8, minute: 0), + initialTime: initialTime ?? const TimeOfDay(hour: 8, minute: 0), ); if (picked != null) { selectedTime = picked; @@ -87,10 +87,10 @@ class DateTimeFormField extends Container { final DateTimeData dateData; final TextEditingController dateController; DateTimeFormField( - {required BuildContext context, + {Key? key, + required BuildContext context, required this.dateData, required this.dateController, - Key? key, FocusNode? focusNode, InputDecoration? decoration = const InputDecoration(), TextInputType? keyboardType = TextInputType.datetime, @@ -135,7 +135,7 @@ class DateTimeFormField extends Container { bool enableIMEPersonalizedLearning = true, double? gapWidth, DateTime? initialDate}) - : super( + : super(key: key, child: Row(children: [ Expanded( child: TextFormField( @@ -168,13 +168,13 @@ class DateTimeFormField extends Container { dateData.onButtonPressed(context, storeSelected: (selected) { dateData.selectedDate = selected; }), - child: Icon(Icons.calendar_today_outlined)), + child: const Icon(Icons.calendar_today_outlined)), SizedBox(width: gapWidth ?? GlobalThemeData.padding), ElevatedButton( onPressed: () => dateData.onButtonPressed(context, storeSelected: (selected) { dateData.selectedDate = selected; }), - child: Icon(Icons.lock_clock_outlined)), + child: const Icon(Icons.lock_clock_outlined)), ])); } diff --git a/lib/widget/message_line.dart b/lib/widget/message_line.dart index ed2f691..d2b9682 100644 --- a/lib/widget/message_line.dart +++ b/lib/widget/message_line.dart @@ -15,13 +15,13 @@ abstract class MessageLine { void addToList(List widgetList, double padding) { if (message.isNotEmpty) { widgetList.add(SizedBox(height: padding)); - widgetList.add(Text(message, style: TextStyle(color: Colors.red))); + widgetList.add(Text(message, style: const TextStyle(color: Colors.red))); } } void addToFormList(List widgetList, double padding) { if (message.isNotEmpty) { - widgetList.add(Text(message, style: TextStyle(color: Colors.red))); + widgetList.add(Text(message, style: const TextStyle(color: Colors.red))); } } } diff --git a/lib/widget/widget_form.dart b/lib/widget/widget_form.dart index 7be3d59..7ca2926 100644 --- a/lib/widget/widget_form.dart +++ b/lib/widget/widget_form.dart @@ -38,12 +38,12 @@ class WidgetForm { Widget rc; if (minWidth > screenWidth) { final widgets = []; - formItems.forEach((element) { + for (var element in formItems) { if (element.gapAbove > 0) { widgets.add(SizedBox(height: element.gapAbove)); } widgets.add(element.widget); - }); + } rc = ListView(children: widgets); } else { int position = 0; @@ -65,7 +65,7 @@ class WidgetForm { } else { if (position < 12 || gap > 0.0) { childrenRow - .add(Expanded(flex: 12 - position, child: SizedBox(width: 1))); + .add(Expanded(flex: 12 - position, child: const SizedBox(width: 1))); } position = 0; if (childrenColumn.isNotEmpty || gap > 0.0) { @@ -84,7 +84,7 @@ class WidgetForm { } if (position < 12) { childrenRow - .add(Expanded(flex: 12 - position, child: SizedBox(width: 1))); + .add(Expanded(flex: 12 - position, child: const SizedBox(width: 1))); } childrenColumn.add(Row(children: childrenRow)); rc = Column(children: childrenColumn); diff --git a/metatool/bin/generator.dart b/metatool/bin/generator.dart index 4da9320..c825b40 100644 --- a/metatool/bin/generator.dart +++ b/metatool/bin/generator.dart @@ -1,9 +1,13 @@ +// ignore_for_file: avoid_print + import 'dart:io'; import 'package:dart_bones/dart_bones.dart'; import 'package:path/path.dart'; +// ignore: avoid_relative_lib_imports import '../lib/meta/module_meta_data.dart'; +// ignore: avoid_relative_lib_imports import '../lib/meta/modules.dart'; import 'generator_base.dart'; import 'page_generator.dart'; @@ -30,7 +34,7 @@ class Generator extends PageGenerator { buffer.writeln("import '../../base/defines.dart';"); buffer.writeln("import '../../base/helper.dart';"); buffer.writeln("import '../../persistence/data_record.dart';"); - final type = 'int'; + const type = 'int'; buffer.writeln( 'class ${module.moduleNameSingular}Data extends DataRecord<$type>{'); for (var item in module.propertyList) { @@ -85,7 +89,7 @@ class Generator extends PageGenerator { '''); buffer.write(''' @override DataMap toMap({DataMap? map, bool clear = true}) { - map ??= DataMap(); + map ??= {}; if (clear) { map.clear(); } @@ -104,6 +108,7 @@ class Generator extends PageGenerator { /// Creates the file modules.dart. String createModules() { + print('= Creating modules.dart: current dir: ' + Directory.current.path); final buffer = StringBuffer(); buffer.write('// DO NOT CHANGE. This file is created by the meta_tool\n'); buffer.write("import 'module_meta_data.dart';\n"); @@ -119,7 +124,7 @@ class Generator extends PageGenerator { fileOfModule[moduleName] = name; modules.add(moduleName); files.add(name); - } + } } modules.sort(); files.sort(); @@ -134,6 +139,7 @@ ModuleMetaData? moduleByName(String name) { switch (name) { '''); for (var module in modules) { + print(module); buffer.write(" case '$module':\n"); final className = findClass(fileOfModule[module]!); buffer.write(" rc = $className();\n"); diff --git a/metatool/bin/meta_tool.dart b/metatool/bin/meta_tool.dart index 603757a..d2f948a 100644 --- a/metatool/bin/meta_tool.dart +++ b/metatool/bin/meta_tool.dart @@ -1,3 +1,5 @@ +// ignore_for_file: avoid_relative_lib_imports + import 'package:dart_bones/dart_bones.dart'; import '../lib/base/i18n_io.dart'; import '../lib/meta/module_meta_data.dart'; diff --git a/metatool/bin/page_generator.dart b/metatool/bin/page_generator.dart index 519d72d..0abbf15 100644 --- a/metatool/bin/page_generator.dart +++ b/metatool/bin/page_generator.dart @@ -1,3 +1,5 @@ +// ignore_for_file: avoid_relative_lib_imports + import 'dart:io'; import 'package:dart_bones/dart_bones.dart'; @@ -11,7 +13,7 @@ import 'sql_generator.dart'; /// Handles the page generation. Is a base class of [Generator]. class PageGenerator extends SqlGenerator { - static final templateBodyLoadData = '''SafeArea( + static const templateBodyLoadData = '''SafeArea( child: FutureBuilder( future: _futureDbData, builder: (context, snapshot) { @@ -21,9 +23,9 @@ class PageGenerator extends SqlGenerator { }); return rc; })));'''; - static final templateBodySimple = '''SafeArea( + static const templateBodySimple = '''SafeArea( child: buildFrame()));'''; - static final templateDidChangeDependencies = ''' + static const templateDidChangeDependencies = ''' @override void didChangeDependencies() { @@ -31,7 +33,7 @@ class PageGenerator extends SqlGenerator { requestRecord(); }'''; - static final templatePage = ''' + static const templatePage = ''' // DO NOT CHANGE. This file is created by the meta_tool! import 'package:flutter/material.dart'; @@ -42,10 +44,10 @@ import 'edit_user_custom.dart'; class EditUserPage extends StatefulWidget { DEF_PRIMARY final PageStates pageStates = PageStates(); - EditUserPage(THIS_PRIMARY) : super(); + EditUserPage(THIS_PRIMARY_COMMA{Key? key}) : super(key: key); @override _EditUserPageState createState() { - final rc = _EditUserPageState(THIS_PRIMARY); + final rc = _EditUserPageState(VAL_PRIMARY); rc.attendedPage = AttendedPage( this, rc, @@ -94,12 +96,12 @@ class _EditUserPageState extends EditUserCustom { } }'''; - static final templateGlobalComboBox = ''' comboRolesFromBackend( + static const templateGlobalComboBox = ''' comboRolesFromBackend( attendedPage: attendedPage, onDone: () => setState(() => 1)); final itemsRoles = comboRoles( i18n.trDyn(GlobalTranslations.combobox#UNDEF), attendedPage);'''; - static final templateListCustom = + static const templateListCustom = '''// This file is created by the meta_tool. But it can be customized. // It will never overridden by the meta_tool. import 'package:flutter/material.dart'; @@ -166,7 +168,7 @@ class ListUserCustom extends State { } Widget buildFrame({required JsonList rows, required int totalCount}){ - final padding = GlobalThemeData.padding; + const padding = GlobalThemeData.padding; #INIT_COMBOS final formItems = [ #FORM_ITEMS FormItem( ElevatedButton( @@ -181,9 +183,9 @@ class ListUserCustom extends State { color: GlobalThemeData.formBackgroundColor, elevation: GlobalThemeData.formElevation, margin: - EdgeInsets.symmetric(vertical: padding, horizontal: padding), + const EdgeInsets.symmetric(vertical: padding, horizontal: padding), child: Padding( - padding: EdgeInsets.symmetric( + padding: const EdgeInsets.symmetric( vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid(formItems, screenWidth: attendedPage.pageStates.screenWidth, @@ -205,7 +207,7 @@ class ListUserCustom extends State { final frameWidget = ListView(children: [ form, if (tabBar != null) tabBar, - SizedBox(height: padding), + const SizedBox(height: padding), SizedBox(width: double.infinity, child: table), ]); return frameWidget; @@ -253,7 +255,7 @@ class _FieldData { #DEF_FIELDS} '''; - static final templateMappingCustom = + static const templateMappingCustom = '''// This file is created by the meta_tool. But it can be customized. // It will never overridden by the meta_tool. import 'package:flutter/material.dart'; @@ -320,7 +322,7 @@ class MappingUserCustom extends State { } Widget buildFrame({required JsonList rows, required int totalCount}){ - final padding = GlobalThemeData.padding; + const padding = GlobalThemeData.padding; #INIT_COMBOS final formItems = [ #FORM_ITEMS FormItem( ElevatedButton( @@ -335,9 +337,9 @@ class MappingUserCustom extends State { color: GlobalThemeData.formBackgroundColor, elevation: GlobalThemeData.formElevation, margin: - EdgeInsets.symmetric(vertical: padding, horizontal: padding), + const EdgeInsets.symmetric(vertical: padding, horizontal: padding), child: Padding( - padding: EdgeInsets.symmetric( + padding: const EdgeInsets.symmetric( vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid(formItems, screenWidth: attendedPage.pageStates.screenWidth, @@ -359,7 +361,7 @@ class MappingUserCustom extends State { final frameWidget = ListView(children: [ form, if (tabBar != null) tabBar, - SizedBox(height: padding), + const SizedBox(height: padding), SizedBox(width: double.infinity, child: table), ]); return frameWidget; @@ -407,7 +409,7 @@ class _FieldData { #DEF_FIELDS} '''; - static final templateRecordCustom = + static const templateRecordCustom = '''// This file is created by the meta_tool. But it can be customized. // It will never overridden by the meta_tool. import 'package:flutter/material.dart'; @@ -431,7 +433,7 @@ class EditUserCustom extends State with MessageLine { final _fieldData = _FieldData(); final GlobalKey _formKey = GlobalKey(debugLabel: 'EditUser'); -#DEF_CONTROLLER EditUserCustom(#THIS_PRIMARY); +#DEF_CONTROLLER EditUserCustom(#VAL_PRIMARY); @override Widget build(BuildContext context) { final rc = Scaffold( @@ -442,7 +444,7 @@ class EditUserCustom extends State with MessageLine { } Widget buildFrame() { - final padding = GlobalThemeData.padding; + const padding = GlobalThemeData.padding; #INIT_COMBO#ASSIGN_CONTROLLER final formItems = [ #FORM_ITEMS FormItem( ElevatedButton( @@ -464,9 +466,9 @@ class EditUserCustom extends State with MessageLine { key: _formKey, child: Card( margin: - EdgeInsets.symmetric(vertical: padding, horizontal: padding), + const EdgeInsets.symmetric(vertical: padding, horizontal: padding), child: Padding( - padding: EdgeInsets.symmetric( + padding: const EdgeInsets.symmetric( vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid( formItems, @@ -510,14 +512,14 @@ class _FieldData { #DEF_FIELD #FROM_MAP#TO_MAP} '''; - static final templateRequestRecord = ''' + static const templateRequestRecord = ''' void requestRecord() => _futureDbData = globalData.restPersistence.query( what: 'query', data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey}); '''; - static final templateStorageDoneCreate = ''' + static const templateStorageDoneCreate = ''' if (answer.startsWith('id:')) { final id = int.tryParse(answer.substring(3)); @@ -530,18 +532,18 @@ class _FieldData { } } '''; - static final templateStorageDoneEdit = ''' + static const templateStorageDoneEdit = ''' requestRecord(); attendedPage.pageStates.dbDataState.clear(); setState(() => 1); '''; - static final templateStorageDoneDelete = + static const templateStorageDoneDelete = "\n globalData.navigate(context, '/#MODULE/list');\n "; - static final templateFromMap = ''' void fromMap(Map map) { + static const templateFromMap = ''' void fromMap(Map map) { #BODY_FROM } '''; - static final templatePageManager = + static const templatePageManager = '''// DO NOT CHANGE. This file is created by the meta_tool! import 'package:flutter/material.dart'; import 'page_manager_custom.dart'; @@ -580,7 +582,7 @@ class PageManager { } '''; - static final templatePageManagerCustom = + static const templatePageManagerCustom = '''// This file is created by the meta_tool. But it can be customized. // It will never overridden by the meta_tool. import 'package:flutter/material.dart'; @@ -596,10 +598,10 @@ StatefulWidget? customPageByRoute(String route) { //final arg1 = parts.length < 2 ? 0 : int.parse(parts[1]); switch (parts[0]) { case '/info': - rc = InfoPage(); + rc = const InfoPage(); break; case '/log': - rc = LogPage(); + rc = const LogPage(); break; default: break; @@ -608,7 +610,7 @@ StatefulWidget? customPageByRoute(String route) { } '''; - static final templateCase = ''' case '/Users/edit': + static const templateCase = ''' case '/Users/edit': rc = EditUserPage(ARG1); break; '''; @@ -925,7 +927,7 @@ StatefulWidget? customPageByRoute(String route) { buffer.writeln(" // please set outside: map[':id'] = primaryKey;"); } for (var field in page.fields) { - if (!(field is PropertyMetaData) || field.hasOption(':primary:')) { + if (field is! PropertyMetaData || field.hasOption(':primary:')) { continue; } final name = field.name; @@ -999,12 +1001,14 @@ StatefulWidget? customPageByRoute(String route) { if (page.pageType == PageType.edit || page.pageType == PageType.delete) { rc = rc .replaceAll('DEF_PRIMARY', ' final int primaryKey;\n') + .replaceAll('THIS_PRIMARY_COMMA', 'this.primaryKey, ') .replaceAll('THIS_PRIMARY', 'this.primaryKey') .replaceAll('PARAM_PRIMARY', 'int primaryKey') .replaceAll('VAL_PRIMARY', 'primaryKey'); } else { rc = rc .replaceAll('DEF_PRIMARY', '') + .replaceAll('THIS_PRIMARY_COMMA', '') .replaceAll('THIS_PRIMARY', '') .replaceAll('PARAM_PRIMARY', '') .replaceAll('VAL_PRIMARY', ''); @@ -1089,6 +1093,7 @@ StatefulWidget? customPageByRoute(String route) { .replaceFirst( '#DEF_PRIMARY', hasPrimary ? ' final int primaryKey;\n' : '') .replaceFirst('#THIS_PRIMARY', hasPrimary ? 'this.primaryKey' : '') + .replaceFirst('#VAL_PRIMARY', hasPrimary ? 'primaryKey' : '') .replaceFirst('#TO_MAP', buildToMap(page)) .replaceFirst('#FROM_MAP', buildFromMap(page)) .replaceFirst('#DEF_FUTURE', definitionFuture) @@ -1136,7 +1141,7 @@ StatefulWidget? customPageByRoute(String route) { .replaceFirst('#IMPORTS#', imports.toString()) .replaceFirst('#CASES#', cases.toString()); writeFile('../lib/page/page_manager.dart', content); - final full = '../lib/page/page_manager_custom.dart'; + const full = '../lib/page/page_manager_custom.dart'; if (File(full).existsSync()) { logger.log('$full already exists. We do not override'); } else { diff --git a/metatool/bin/sql_generator.dart b/metatool/bin/sql_generator.dart index 9826a6d..cf118de 100644 --- a/metatool/bin/sql_generator.dart +++ b/metatool/bin/sql_generator.dart @@ -1,3 +1,5 @@ +// ignore_for_file: avoid_relative_lib_imports + import 'dart:io'; import 'package:dart_bones/dart_bones.dart'; @@ -166,7 +168,7 @@ update: separator: first ? null : ',', indent: 4, buffer: parameters); - addToBuffer('${item.columnName}', + addToBuffer(item.columnName, maxLength: 80, separator: first ? null : ',', indent: 6, diff --git a/metatool/pubspec.yaml b/metatool/pubspec.yaml index 0d8234a..ba38db8 100644 --- a/metatool/pubspec.yaml +++ b/metatool/pubspec.yaml @@ -15,6 +15,6 @@ dependencies: dart_bones: ^1.2.2 dev_dependencies: - pedantic: ^1.11.1 + lints: ^1.0.1 test: ^1.17.10 - + flutter_lints: ^1.0.4 diff --git a/rest_server/data/sql/scopes.sql.yaml b/rest_server/data/sql/scopes.sql.yaml new file mode 100644 index 0000000..0c4be91 --- /dev/null +++ b/rest_server/data/sql/scopes.sql.yaml @@ -0,0 +1,39 @@ +--- +# DO NOT CHANGE. This file is created by the meta_tool +# SQL statements of the module "Scopes": + +module: Scopes +list: + type: list + parameters: [] + order: "scope_id" + sql: | + SELECT + t0.* + FROM scopes t0 +byId: + type: record + parameters: [ ":id" ] + sql: "SELECT * FROM scopes WHERE scope_id=:id;" +delete: + type: delete + parameters: [ ":id" ] + sql: "DELETE * FROM scopes WHERE scope_id=:id;" +update: + type: update + parameters: [":id",":scope",":name",":value",":position"] + sql: | + UPDATE scopes SET + scope_scope=:scope, + scope_name=:name, + scope_value=:value, + scope_position=:position, + scope_changedat=NOW() + WHERE scope_id=:id; +insert: + type: insert + parameters: [":scope",":name",":value",":position",":createdBy"] + sql: | + INSERT INTO scopes(scope_scope,scope_name,scope_value,scope_position, + scope_createdby,scope_createdat) + VALUES(:scope,:name,:value,:position,:createdBy,NOW()); diff --git a/rest_server/data/sql/users.sql.yaml b/rest_server/data/sql/users.sql.yaml index c399079..8d7c06e 100644 --- a/rest_server/data/sql/users.sql.yaml +++ b/rest_server/data/sql/users.sql.yaml @@ -9,9 +9,10 @@ list: order: "user_id" sql: | SELECT - t0.*,t1.role_name AS role + t0.*,t1.role_name AS role,t2.role_name AS role FROM users t0 JOIN roles t1 ON t1.role_id=t0.user_role + JOIN roles t2 ON t2.role_id=t0.user_status WHERE (:text='' OR user_name like :text OR user_displayname like :text OR user_email like :text) @@ -26,19 +27,20 @@ delete: sql: "DELETE * FROM users WHERE user_id=:id;" update: type: update - parameters: [":id",":name",":displayName",":email",":role"] + parameters: [":id",":name",":displayName",":email",":role",":status"] sql: | UPDATE users SET user_name=:name, user_displayname=:displayName, user_email=:email, user_role=:role, + user_status=:status, user_changedat=NOW() WHERE user_id=:id; insert: type: insert - parameters: [":name",":displayName",":email",":role",":createdBy"] + parameters: [":name",":displayName",":email",":role",":status",":createdBy"] sql: | INSERT INTO users(user_name,user_displayname,user_email,user_role, - user_createdby,user_createdat) - VALUES(:name,:displayName,:email,:role,:createdBy,NOW()); + user_status,user_createdby,user_createdat) + VALUES(:name,:displayName,:email,:role,:status,:createdBy,NOW()); diff --git a/rest_server/lib/rest_server.dart b/rest_server/lib/rest_server.dart index da0afd5..1fe307c 100644 --- a/rest_server/lib/rest_server.dart +++ b/rest_server/lib/rest_server.dart @@ -194,7 +194,7 @@ db: timeout: 30 traceDataLength: 200 clientSessionTimeout: 900 -# put this content to /etc/exhibition/exhibition.yaml +# put this content to /etc/exhibition/exhibition.sv.yaml '''; return rc; } @@ -215,7 +215,7 @@ clientSessionTimeout: 900 if (!executable.startsWith(Platform.pathSeparator)) { executable = processSync.executeToString('which', [executable]).trim(); } - final fnConfig = '/etc/exhibition/$appName.yaml'; + final fnConfig = '/etc/exhibition/$appName.sv.yaml'; fileSync.ensureDirectory(path.dirname(fnConfig)); if (File(fnConfig).existsSync()) { logger.log('= $fnConfig already exists.');