feat(import): enhance recipe creation by passing both markdown and image URL from import
This commit is contained in:
@@ -68,8 +68,20 @@ final appRouterProvider = Provider<GoRouter>((ref) {
|
|||||||
GoRoute(
|
GoRoute(
|
||||||
path: '/recipes/create',
|
path: '/recipes/create',
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
final initialMarkdown = state.extra as String?;
|
final extra = state.extra;
|
||||||
return CreateRecipeScreen(initialMarkdown: initialMarkdown);
|
String? initialMarkdown;
|
||||||
|
String? initialImageUrl;
|
||||||
|
if (extra is Map<String, dynamic>) {
|
||||||
|
initialMarkdown = extra['markdown'] as String?;
|
||||||
|
initialImageUrl = extra['imageUrl'] as String?;
|
||||||
|
} else if (extra is String) {
|
||||||
|
// Backwards-compat: plain string means markdown only.
|
||||||
|
initialMarkdown = extra;
|
||||||
|
}
|
||||||
|
return CreateRecipeScreen(
|
||||||
|
initialMarkdown: initialMarkdown,
|
||||||
|
initialImageUrl: initialImageUrl,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
|
|||||||
@@ -78,8 +78,11 @@ class _RecipeImportTabState extends ConsumerState<RecipeImportTab> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
// Pass markdown as GoRouter extra — CreateRecipeScreen picks it up.
|
// Pass both markdown and imageUrl so CreateRecipeScreen can pre-fill both.
|
||||||
context.push('/recipes/create', extra: result.markdown);
|
context.push('/recipes/create', extra: {
|
||||||
|
'markdown': result.markdown,
|
||||||
|
'imageUrl': result.imageUrl,
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
setState(() => _error = mapErrorToUserMessage(e, context));
|
setState(() => _error = mapErrorToUserMessage(e, context));
|
||||||
|
|||||||
@@ -14,7 +14,14 @@ class CreateRecipeScreen extends ConsumerStatefulWidget {
|
|||||||
/// Optional markdown to pre-fill the input field, e.g. from import.
|
/// Optional markdown to pre-fill the input field, e.g. from import.
|
||||||
final String? initialMarkdown;
|
final String? initialMarkdown;
|
||||||
|
|
||||||
const CreateRecipeScreen({super.key, this.initialMarkdown});
|
/// Optional image URL pre-filled from a quick-import result.
|
||||||
|
final String? initialImageUrl;
|
||||||
|
|
||||||
|
const CreateRecipeScreen({
|
||||||
|
super.key,
|
||||||
|
this.initialMarkdown,
|
||||||
|
this.initialImageUrl,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ConsumerState<CreateRecipeScreen> createState() =>
|
ConsumerState<CreateRecipeScreen> createState() =>
|
||||||
@@ -143,6 +150,8 @@ class _CreateRecipeScreenState extends ConsumerState<CreateRecipeScreen> {
|
|||||||
if (servingsRaw != null) 'servings': servingsRaw,
|
if (servingsRaw != null) 'servings': servingsRaw,
|
||||||
if (_parsed!.instructions != null)
|
if (_parsed!.instructions != null)
|
||||||
'instructions': _parsed!.instructions,
|
'instructions': _parsed!.instructions,
|
||||||
|
if (widget.initialImageUrl != null && widget.initialImageUrl!.isNotEmpty)
|
||||||
|
'imageUrl': widget.initialImageUrl,
|
||||||
'ingredients': ingredients,
|
'ingredients': ingredients,
|
||||||
},
|
},
|
||||||
token: token,
|
token: token,
|
||||||
|
|||||||
Reference in New Issue
Block a user