Skip to content

Commit

Permalink
lint: make dart format pass verification
Browse files Browse the repository at this point in the history
  • Loading branch information
wfleischer committed Nov 8, 2024
1 parent 32a0c59 commit 2159c54
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import 'package:nwt_reading/src/bible_languages/entities/bible_languages.dart';
class BibleLanguagesDeserializer {
BibleLanguages convertJsonToBibleLanguages(String json) {
final bibleLanguagesMap = jsonDecode(json) as Map<String, dynamic>;
final bibleLanguages = Map<String, BibleLanguage>.from(bibleLanguagesMap
.map((bibleLanguageKey, bibleLanguageMap) =>
MapEntry(bibleLanguageKey,
_convertMapToBibleLanguage(bibleLanguageMap as Map<String, dynamic>))));
final bibleLanguages = Map<String, BibleLanguage>.from(
bibleLanguagesMap.map((bibleLanguageKey, bibleLanguageMap) => MapEntry(
bibleLanguageKey,
_convertMapToBibleLanguage(
bibleLanguageMap as Map<String, dynamic>))));

return BibleLanguages(bibleLanguages);
}
Expand Down
25 changes: 13 additions & 12 deletions lib/src/plans/entities/plans.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,25 @@ class PlansNotifier extends Notifier<Plans> {

String getNewPlanId() => _uuid.v4();

String getDefaultName(ScheduleKey scheduleKey) => '${toBeginningOfSentenceCase(scheduleKey.type.name)} ${scheduleKey.duration.name}';
String getDefaultName(ScheduleKey scheduleKey) =>
'${toBeginningOfSentenceCase(scheduleKey.type.name)} ${scheduleKey.duration.name}';

Plan getNewPlan(String planId) {
const scheduleKey = ScheduleKey(
type: ScheduleType.chronological,
duration: ScheduleDuration.y1,
version: '1.0');
type: ScheduleType.chronological,
duration: ScheduleDuration.y1,
version: '1.0');
final name = getDefaultName(scheduleKey);

return Plan(
id: planId,
name: name,
scheduleKey: scheduleKey,
language: 'en',
bookmark: const Bookmark(dayIndex: 0, sectionIndex: -1),
withTargetDate: true,
showEvents: true,
showLocations: true);
id: planId,
name: name,
scheduleKey: scheduleKey,
language: 'en',
bookmark: const Bookmark(dayIndex: 0, sectionIndex: -1),
withTargetDate: true,
showEvents: true,
showLocations: true);
}

void addPlan(Plan plan) {
Expand Down
17 changes: 9 additions & 8 deletions lib/src/plans/presentations/plan_edit_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ class PlanEditDialog extends ConsumerWidget {
const SizedBox(height: 20),
PlanLanguageTile(planId),
PlanWithTargetDateTile(planId),
if (!isNewPlan) ElevatedButton.icon(
onPressed: () {
planEdit.delete();
Navigator.popUntil(
context, ModalRoute.withName(PlansPage.routeName));
},
icon: const Icon(Icons.delete),
label: const Text('Delete'))
if (!isNewPlan)
ElevatedButton.icon(
onPressed: () {
planEdit.delete();
Navigator.popUntil(
context, ModalRoute.withName(PlansPage.routeName));
},
icon: const Icon(Icons.delete),
label: const Text('Delete'))
],
),
));
Expand Down
9 changes: 6 additions & 3 deletions lib/src/plans/repositories/plans_deserializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import 'package:nwt_reading/src/schedules/entities/schedules.dart';
class PlansDeserializer {
Plans convertStringListToPlans(List<String>? plansStringList) =>
Plans((plansStringList ?? [])
.map((planJson) => _convertMapToPlan(jsonDecode(planJson) as Map<String, dynamic>))
.map((planJson) =>
_convertMapToPlan(jsonDecode(planJson) as Map<String, dynamic>))
.toList());

ScheduleKey convertMapToScheduleKey(Map<String, dynamic> scheduleKeyMap) {
Expand All @@ -25,9 +26,11 @@ class PlansDeserializer {
Plan _convertMapToPlan(Map<String, dynamic> planMap) {
final id = planMap['id'] as String;
final name = planMap['name'] as String;
final schedule = convertMapToScheduleKey(planMap['scheduleKey'] as Map<String, dynamic>);
final schedule =
convertMapToScheduleKey(planMap['scheduleKey'] as Map<String, dynamic>);
final language = planMap['language'] as String;
final bookmark = _convertMapToBookmark(planMap['bookmark'] as Map<String, dynamic>);
final bookmark =
_convertMapToBookmark(planMap['bookmark'] as Map<String, dynamic>);
final startDate = planMap['startDate'] == null
? null
: DateTime.parse(planMap['startDate'] as String);
Expand Down
8 changes: 6 additions & 2 deletions lib/src/plans/repositories/plans_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ class PlansRepository {
final scheduleKey = ScheduleKey(
type: ScheduleType.values.byName(currentSchedule),
duration: ScheduleDuration.values.byName(
(schedule['duration'] as String? ?? '1y').split('').reversed.join('')),
(schedule['duration'] as String? ?? '1y')
.split('')
.reversed
.join('')),
version: '1.0');
final bookmark = Bookmark(
dayIndex: int.tryParse(schedule['readIndex'] as String? ?? '0') ?? 0,
dayIndex:
int.tryParse(schedule['readIndex'] as String? ?? '0') ?? 0,
sectionIndex: -1);
final DateTime? targetDate =
withTargetDate && schedule['endDate'] != null
Expand Down
12 changes: 6 additions & 6 deletions lib/src/plans/stories/plan_edit_story.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class PlanEdit extends AutoDisposeFamilyNotifier<Plan, String?> {
void changeName(String name) => _name = name;

void updateDefaultName(ScheduleKey scheduleKey) {
final plansNotifier = ref.read(plansProvider.notifier);
final isDefaultName = _name == null ||
_name == plansNotifier.getDefaultName(state.scheduleKey);
final plansNotifier = ref.read(plansProvider.notifier);
final isDefaultName = _name == null ||
_name == plansNotifier.getDefaultName(state.scheduleKey);

if (isDefaultName) {
_name = plansNotifier.getDefaultName(scheduleKey);
}
if (isDefaultName) {
_name = plansNotifier.getDefaultName(scheduleKey);
}
}

void updateLanguage(String language) {
Expand Down
7 changes: 5 additions & 2 deletions lib/src/schedules/presentations/section_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class SectionWidget extends ConsumerWidget {
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('Confirm toggling read'),
content: const Text('Do you want to set all prior sections as been read and all following to unread?'),
content: const Text(
'Do you want to set all prior sections as been read and all following to unread?'),
actions: <Widget>[
TextButton(
key: const Key('reject-toggle-read'),
Expand All @@ -52,7 +53,9 @@ class SectionWidget extends ConsumerWidget {
key: const Key('confirm-toggle-read'),
onPressed: () {
planNotifier.toggleRead(
dayIndex: dayIndex, sectionIndex: sectionIndex, force: true);
dayIndex: dayIndex,
sectionIndex: sectionIndex,
force: true);
Navigator.pop(context, 'OK');
},
child: const Text('OK'),
Expand Down
6 changes: 3 additions & 3 deletions lib/src/schedules/repositories/events_deserializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import 'package:nwt_reading/src/schedules/entities/events.dart';
class EventsDeserializer {
Events convertJsonToEvents(String json) {
final eventsMap = jsonDecode(json) as Map<String, dynamic>;
final events = Map<String, Event>.from(eventsMap.map(
(eventKey, eventMap) =>
MapEntry(eventKey, _convertMapToEvent(eventMap as Map<String, dynamic>))));
final events = Map<String, Event>.from(eventsMap.map((eventKey, eventMap) =>
MapEntry(
eventKey, _convertMapToEvent(eventMap as Map<String, dynamic>))));

return Events(events);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/schedules/repositories/locations_deserializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class LocationsDeserializer {
Locations convertJsonToLocations(String json) {
final locationsMap = jsonDecode(json) as Map<String, dynamic>;
final locations = Map<String, Location>.from(locationsMap.map(
(locationKey, locationMap) =>
MapEntry(locationKey, _convertMapToLocation(locationMap as Map<String, dynamic>))));
(locationKey, locationMap) => MapEntry(locationKey,
_convertMapToLocation(locationMap as Map<String, dynamic>))));

return Locations(locations);
}
Expand Down
12 changes: 8 additions & 4 deletions lib/src/schedules/repositories/schedule_deserializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import 'package:nwt_reading/src/schedules/entities/schedules.dart';
class ScheduleDeserializer {
Schedule convertJsonToSchedule(String json) {
final dayList = jsonDecode(json) as List<dynamic>;
final days = List<Day>.from(dayList.map((dayMap) => _convertMapToDay(dayMap as List<dynamic>)));
final days = List<Day>.from(
dayList.map((dayMap) => _convertMapToDay(dayMap as List<dynamic>)));

return Schedule(days);
}

Day _convertMapToDay(List<dynamic> dayMap) {
final sections =
dayMap.map((sectionMap) => _convertMapToSection(sectionMap as Map<String, dynamic>)).toList();
final sections = dayMap
.map((sectionMap) =>
_convertMapToSection(sectionMap as Map<String, dynamic>))
.toList();

return Day(List<Section>.from(sections));
}
Expand All @@ -26,7 +29,8 @@ class ScheduleDeserializer {
final endIndex = sectionMap['endIndex'] as int;
final url = sectionMap['url'] as String;
final events = List<String>.from(sectionMap['events'] as List<dynamic>);
final locations = List<String>.from(sectionMap['locations'] as List<dynamic>);
final locations =
List<String>.from(sectionMap['locations'] as List<dynamic>);

return Section(
bookIndex: bookIndex,
Expand Down

0 comments on commit 2159c54

Please sign in to comment.