Skip to content

Commit

Permalink
Force the TestData option to become available as long as we are devel…
Browse files Browse the repository at this point in the history
…oping.
  • Loading branch information
hjtappe committed Dec 4, 2024
1 parent bf6f9f8 commit c428275
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 12 deletions.
6 changes: 3 additions & 3 deletions lib/data/appProviders/preferences_provider.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:iccm_eu_app/data/dataProviders/events_provider.dart';
import 'package:shared_preferences/shared_preferences.dart' show SharedPreferences;

class PreferencesProvider {
Expand Down Expand Up @@ -75,15 +75,15 @@ class PreferencesProvider {

static Future<void> loadUseTestData() async {
bool value = false;
if (kDebugMode) {
if (EventsProvider.showTestDataOption()) {
final prefs = await SharedPreferences.getInstance();
value = prefs.getBool(_useTestDataKey) ?? false; // Default
}
useTestDataNotifier.value = value;
}

static Future<void> setUseTestData(bool value) async {
if (kDebugMode) {
if (EventsProvider.showTestDataOption()) {
useTestDataNotifier.value = value;
final prefs = await SharedPreferences.getInstance();
await prefs.setBool(_useTestDataKey, value);
Expand Down
10 changes: 9 additions & 1 deletion lib/data/dataProviders/events_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class EventsProvider with ChangeNotifier {
}

void updateCache() {
if (kDebugMode && PreferencesProvider.useTestDataNotifier.value) {
if (EventsProvider.showTestDataOption() &&
PreferencesProvider.useTestDataNotifier.value) {
_cacheClear();
for (EventData item in TestData.getEvents()) {
_cacheAdd(item);
Expand Down Expand Up @@ -282,4 +283,11 @@ class EventsProvider with ChangeNotifier {
return next.start;
}
}

static bool showTestDataOption() {
bool value = kDebugMode;
// Overwrite during development
value = true;
return value;
}
}
3 changes: 2 additions & 1 deletion lib/data/dataProviders/gsheets_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ class GsheetsProvider with ChangeNotifier {
return;
}

if (!kDebugMode || !PreferencesProvider.useTestDataNotifier.value) {
if (!EventsProvider.showTestDataOption() ||
!PreferencesProvider.useTestDataNotifier.value) {
List<String> workSheetTitles = [];
workSheetTitles.add(EventsProvider.worksheetTitle);
workSheetTitles.add(RoomsProvider.worksheetTitle);
Expand Down
4 changes: 3 additions & 1 deletion lib/data/dataProviders/rooms_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';

import 'package:flutter/foundation.dart';
import 'package:iccm_eu_app/data/appProviders/preferences_provider.dart';
import 'package:iccm_eu_app/data/dataProviders/events_provider.dart';
import 'package:iccm_eu_app/data/dataProviders/gsheets_provider.dart';
import 'package:iccm_eu_app/data/definitions/item_colors_dictionary.dart';
import 'package:iccm_eu_app/data/model/room_data.dart';
Expand Down Expand Up @@ -31,7 +32,8 @@ class RoomsProvider with ChangeNotifier {
}

void updateCache() {
if (kDebugMode && PreferencesProvider.useTestDataNotifier.value) {
if (EventsProvider.showTestDataOption() &&
PreferencesProvider.useTestDataNotifier.value) {
_cacheClear();
for (RoomData item in TestData.rooms) {
_cacheAdd(item);
Expand Down
4 changes: 3 additions & 1 deletion lib/data/dataProviders/speakers_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';

import 'package:flutter/foundation.dart';
import 'package:iccm_eu_app/data/appProviders/preferences_provider.dart';
import 'package:iccm_eu_app/data/dataProviders/events_provider.dart';
import 'package:iccm_eu_app/data/dataProviders/gsheets_provider.dart';
import 'package:iccm_eu_app/data/model/speaker_data.dart';
import 'package:iccm_eu_app/data/testData/test_data.dart';
Expand Down Expand Up @@ -29,7 +30,8 @@ class SpeakersProvider with ChangeNotifier {
}

void updateCache() {
if (kDebugMode && PreferencesProvider.useTestDataNotifier.value) {
if (EventsProvider.showTestDataOption() &&
PreferencesProvider.useTestDataNotifier.value) {
_cacheClear();
for (SpeakerData item in TestData.speakers) {
_cacheAdd(item);
Expand Down
4 changes: 3 additions & 1 deletion lib/data/dataProviders/tracks_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';

import 'package:flutter/foundation.dart';
import 'package:iccm_eu_app/data/appProviders/preferences_provider.dart';
import 'package:iccm_eu_app/data/dataProviders/events_provider.dart';
import 'package:iccm_eu_app/data/dataProviders/gsheets_provider.dart';
import 'package:iccm_eu_app/data/definitions/item_colors_dictionary.dart';
import 'package:iccm_eu_app/data/model/track_data.dart';
Expand Down Expand Up @@ -33,7 +34,8 @@ class TracksProvider with ChangeNotifier {
}

void updateCache() {
if (kDebugMode && PreferencesProvider.useTestDataNotifier.value) {
if (EventsProvider.showTestDataOption() &&
PreferencesProvider.useTestDataNotifier.value) {
Debug.msg("Updating TrackData cache from TestData ($kDebugMode, ${PreferencesProvider.useTestDataNotifier.value}).");
_cacheClear();
for (TrackData item in TestData.tracks) {
Expand Down
8 changes: 4 additions & 4 deletions lib/pages/preferences_page.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:iccm_eu_app/components/toggle_button.dart';
import 'package:iccm_eu_app/components/toggle_is_dark_mode.dart';
import 'package:iccm_eu_app/data/appProviders/preferences_provider.dart';
import 'package:iccm_eu_app/data/dataProviders/error_provider.dart';
import 'package:iccm_eu_app/data/dataProviders/events_provider.dart';
import 'package:iccm_eu_app/data/dataProviders/gsheets_provider.dart';
import 'package:provider/provider.dart';

Expand Down Expand Up @@ -73,11 +73,11 @@ class PreferencesPage extends StatelessWidget {
);
},
),
if (kDebugMode)
if (EventsProvider.showTestDataOption())
const Divider()
else
const SizedBox.shrink(),
if (kDebugMode)
if (EventsProvider.showTestDataOption())
Text('Test Data',
style: Theme
.of(context)
Expand All @@ -86,7 +86,7 @@ class PreferencesPage extends StatelessWidget {
)
else
const SizedBox.shrink(),
if (kDebugMode)
if (EventsProvider.showTestDataOption())
ValueListenableBuilder<bool>(
valueListenable: PreferencesProvider.useTestDataNotifier,
builder: (context, builderValue, child) {
Expand Down

0 comments on commit c428275

Please sign in to comment.