mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 02:39:19 +08:00
Implemented Flutter Code Export Functionality
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:apidash/services/agentic_services/agent_caller.dart';
|
|||||||
import 'package:apidash/widgets/widget_sending.dart';
|
import 'package:apidash/widgets/widget_sending.dart';
|
||||||
import 'package:apidash_design_system/apidash_design_system.dart';
|
import 'package:apidash_design_system/apidash_design_system.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:genai/agentic_engine/blueprint.dart';
|
import 'package:genai/agentic_engine/blueprint.dart';
|
||||||
import 'package:stac/stac.dart' as stac;
|
import 'package:stac/stac.dart' as stac;
|
||||||
@@ -245,17 +246,19 @@ class _FrameWorkSelectorPageState extends State<FrameWorkSelectorPage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SDUIPreviewPage extends StatefulWidget {
|
class SDUIPreviewPage extends ConsumerStatefulWidget {
|
||||||
final String sduiCode;
|
final String sduiCode;
|
||||||
final Function() onNext;
|
final Function() onNext;
|
||||||
const SDUIPreviewPage(
|
const SDUIPreviewPage(
|
||||||
{super.key, required this.onNext, required this.sduiCode});
|
{super.key, required this.onNext, required this.sduiCode});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<SDUIPreviewPage> createState() => _SDUIPreviewPageState();
|
ConsumerState<SDUIPreviewPage> createState() => _SDUIPreviewPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SDUIPreviewPageState extends State<SDUIPreviewPage> {
|
class _SDUIPreviewPageState extends ConsumerState<SDUIPreviewPage> {
|
||||||
|
bool exportingCode = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
@@ -288,6 +291,7 @@ class _SDUIPreviewPageState extends State<SDUIPreviewPage> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
kVSpacer20,
|
kVSpacer20,
|
||||||
|
if (!exportingCode) ...[
|
||||||
Container(
|
Container(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
@@ -310,18 +314,41 @@ class _SDUIPreviewPageState extends State<SDUIPreviewPage> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
kVSpacer20,
|
kVSpacer20,
|
||||||
|
],
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
children: [
|
children: [
|
||||||
Align(
|
Align(
|
||||||
alignment: Alignment.centerRight,
|
alignment: Alignment.centerRight,
|
||||||
child: FilledButton.tonalIcon(
|
child: (exportingCode)
|
||||||
|
? Container(
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
strokeWidth: 1,
|
||||||
|
),
|
||||||
|
margin: EdgeInsets.only(right: 10),
|
||||||
|
)
|
||||||
|
: FilledButton.tonalIcon(
|
||||||
style: FilledButton.styleFrom(
|
style: FilledButton.styleFrom(
|
||||||
padding: kPh12,
|
padding: kPh12,
|
||||||
minimumSize: const Size(44, 44),
|
minimumSize: const Size(44, 44),
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () async {
|
||||||
widget.onNext();
|
setState(() {
|
||||||
|
exportingCode = true;
|
||||||
|
});
|
||||||
|
final ans = await APIDashAgentCaller.instance.call(
|
||||||
|
StacToFlutterBot(),
|
||||||
|
ref: ref,
|
||||||
|
input: AgentInputs(
|
||||||
|
variables: {'VAR_CODE': widget.sduiCode}),
|
||||||
|
);
|
||||||
|
final exportedCode = ans['CODE'];
|
||||||
|
Clipboard.setData(ClipboardData(text: ans['CODE']));
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text("Copied to clipboard!")));
|
||||||
|
setState(() {
|
||||||
|
exportingCode = false;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
Icons.download,
|
Icons.download,
|
||||||
@@ -334,6 +361,7 @@ class _SDUIPreviewPageState extends State<SDUIPreviewPage> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
kHSpacer10,
|
kHSpacer10,
|
||||||
|
if (!exportingCode)
|
||||||
Align(
|
Align(
|
||||||
alignment: Alignment.centerRight,
|
alignment: Alignment.centerRight,
|
||||||
child: FilledButton.tonalIcon(
|
child: FilledButton.tonalIcon(
|
||||||
|
|||||||
Reference in New Issue
Block a user