-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
1,968 additions
and
1,865 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
import '../../cook_page/recipe_list.dart'; | ||
import '../../farm_page/farm_page_model.dart'; | ||
import '../app.dart'; | ||
|
||
typedef CreateRecipeListRepository = RecipeListRepository Function(BuildContext); | ||
|
||
/// Boot the app. | ||
/// | ||
/// If you want to overwrite the defaults, pass the optional parameters. | ||
void bootApp({ | ||
CreateRecipeListRepository? recipeListRepository, | ||
}) async { | ||
await _clearPrefsIfNeeds(); | ||
|
||
FlutterError.onError = (details) { | ||
FlutterError.presentError(details); | ||
}; | ||
|
||
runApp( | ||
MultiProvider( | ||
providers: [ | ||
Provider( | ||
create: (context) => SharedPreferencesWithCache.create( | ||
cacheOptions: const SharedPreferencesWithCacheOptions( | ||
allowList: { | ||
RecipeListRepository.key, | ||
FarmPageRepository.key, | ||
}, | ||
), | ||
), | ||
), | ||
Provider( | ||
create: recipeListRepository ?? | ||
(context) => RecipeListRepository( | ||
prefs: context.read(), | ||
), | ||
), | ||
Provider( | ||
create: (context) => FarmPageRepository( | ||
prefs: context.read(), | ||
), | ||
), | ||
], | ||
child: const App(), | ||
), | ||
); | ||
} | ||
|
||
Future<void> _clearPrefsIfNeeds() async { | ||
WidgetsFlutterBinding.ensureInitialized(); | ||
final prefs = await SharedPreferencesWithCache.create(cacheOptions: const SharedPreferencesWithCacheOptions()); | ||
|
||
// 버전 명시 | ||
const currentVersion = _PrefsVersion( | ||
description: 'Update farm card model', | ||
number: 15, | ||
); | ||
|
||
Future<void> clearAndSet() async { | ||
await prefs.clear(); | ||
prefs.setInt('prefs_version', currentVersion.number); | ||
} | ||
|
||
final existingVersion = prefs.getInt('prefs_version'); | ||
if (existingVersion == null) { | ||
clearAndSet(); | ||
return; | ||
} | ||
assert(existingVersion <= currentVersion.number); | ||
if (existingVersion < currentVersion.number) { | ||
clearAndSet(); | ||
return; | ||
} | ||
} | ||
|
||
class _PrefsVersion { | ||
final String description; | ||
final int number; | ||
|
||
const _PrefsVersion({required this.description, required this.number}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart'; | ||
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart'; | ||
|
||
import '../boot_app.dart'; | ||
|
||
void main() async { | ||
SharedPreferencesAsyncPlatform.instance = InMemorySharedPreferencesAsync.empty(); | ||
bootApp(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import '../boot_app.dart'; | ||
|
||
void main() async { | ||
bootApp(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.