Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
woin2ee committed Feb 23, 2025
2 parents fdc7893 + 08c7278 commit d5183da
Show file tree
Hide file tree
Showing 39 changed files with 1,968 additions and 1,865 deletions.
20 changes: 15 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,37 @@
"version": "0.2.0",
"configurations": [
{
"name": "Flutter for Chrome",
"name": "Run on Chrome",
"request": "launch",
"type": "dart",
"program": "lib/main.dart",
"program": "lib/app/entry_point/release/main.dart",
"args": [
"-d",
"chrome",
]
},
{
"name": "Flutter for MacOS",
"name": "Run on MacOS",
"request": "launch",
"type": "dart",
"program": "lib/main.dart",
"program": "lib/app/entry_point/release/main.dart",
"args": [
"-d",
"macos",
]
},
{
"name": "Flutter(example) for MacOS",
"name": "Run on MacOS(Sample data)",
"request": "launch",
"type": "dart",
"program": "lib/app/entry_point/debug/main.dart",
"args": [
"-d",
"macos",
]
},
{
"name": "Run(example) on MacOS",
"request": "launch",
"type": "dart",
"program": "example/main.dart",
Expand Down
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ analyzer:
exclude:
- lib/**.freezed.dart
- lib/**.g.dart
- lib/l10n/gen
- lib/l10n/gen/**

linter:
# The lint rules applied to this project can be customized in the
Expand Down
85 changes: 85 additions & 0 deletions lib/app/entry_point/boot_app.dart
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});
}
9 changes: 9 additions & 0 deletions lib/app/entry_point/debug/main.dart
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();
}
5 changes: 5 additions & 0 deletions lib/app/entry_point/release/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import '../boot_app.dart';

void main() async {
bootApp();
}
26 changes: 25 additions & 1 deletion lib/app/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,44 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:material_symbols_icons/symbols.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../l10n/l10ns.dart';
import '../cook_page/cook_page.dart';
import '../farm_page/farm_page.dart';
import '../utils/custom_icon/custom_icon_icons.dart';
import '../utils/font_family.dart';
import 'app_state.dart';
import 'models/menu.dart';

enum AvailableLanguage {
en,
ko,
}

enum Menu {
farm,
cook;

String localized(BuildContext context) {
switch (this) {
case Menu.farm:
return L10ns.of(context).localized('menu_farm');
case Menu.cook:
return L10ns.of(context).localized('menu_cook');
}
}

Widget get icon {
switch (this) {
case Menu.farm:
return const Icon(Icons.grid_4x4);
case Menu.cook:
return const Icon(Symbols.cooking);
}
}
}

class HomePage extends StatefulWidget {
const HomePage({
super.key,
Expand Down
27 changes: 0 additions & 27 deletions lib/app/models/menu.dart

This file was deleted.

Loading

0 comments on commit d5183da

Please sign in to comment.