mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 10:49:49 +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,72 +291,97 @@ class _SDUIPreviewPageState extends State<SDUIPreviewPage> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
kVSpacer20,
|
kVSpacer20,
|
||||||
Container(
|
if (!exportingCode) ...[
|
||||||
width: double.infinity,
|
Container(
|
||||||
decoration: BoxDecoration(
|
width: double.infinity,
|
||||||
color: Colors.black, // Dark background
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(15),
|
color: Colors.black, // Dark background
|
||||||
border: Border.all(
|
borderRadius: BorderRadius.circular(15),
|
||||||
color: Colors.grey, // Border color
|
border: Border.all(
|
||||||
width: 1,
|
color: Colors.grey, // Border color
|
||||||
|
width: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: TextField(
|
||||||
|
maxLines: 3, // Makes the text box taller
|
||||||
|
style: TextStyle(color: Colors.white), // White text
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: 'Any Modifications?',
|
||||||
|
hintStyle: TextStyle(color: Colors.grey), // Grey hint text
|
||||||
|
border: InputBorder.none, // Removes the default border
|
||||||
|
contentPadding: EdgeInsets.all(16), // Padding inside the box
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: TextField(
|
kVSpacer20,
|
||||||
maxLines: 3, // Makes the text box taller
|
],
|
||||||
style: TextStyle(color: Colors.white), // White text
|
|
||||||
decoration: InputDecoration(
|
|
||||||
hintText: 'Any Modifications?',
|
|
||||||
hintStyle: TextStyle(color: Colors.grey), // Grey hint text
|
|
||||||
border: InputBorder.none, // Removes the default border
|
|
||||||
contentPadding: EdgeInsets.all(16), // Padding inside the box
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
kVSpacer20,
|
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
children: [
|
children: [
|
||||||
Align(
|
Align(
|
||||||
alignment: Alignment.centerRight,
|
alignment: Alignment.centerRight,
|
||||||
child: FilledButton.tonalIcon(
|
child: (exportingCode)
|
||||||
style: FilledButton.styleFrom(
|
? Container(
|
||||||
padding: kPh12,
|
child: CircularProgressIndicator(
|
||||||
minimumSize: const Size(44, 44),
|
strokeWidth: 1,
|
||||||
),
|
),
|
||||||
onPressed: () {
|
margin: EdgeInsets.only(right: 10),
|
||||||
widget.onNext();
|
)
|
||||||
},
|
: FilledButton.tonalIcon(
|
||||||
icon: Icon(
|
style: FilledButton.styleFrom(
|
||||||
Icons.download,
|
padding: kPh12,
|
||||||
),
|
minimumSize: const Size(44, 44),
|
||||||
label: const SizedBox(
|
),
|
||||||
child: Text(
|
onPressed: () async {
|
||||||
"Export Code",
|
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(
|
||||||
|
Icons.download,
|
||||||
|
),
|
||||||
|
label: const SizedBox(
|
||||||
|
child: Text(
|
||||||
|
"Export Code",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
kHSpacer10,
|
kHSpacer10,
|
||||||
Align(
|
if (!exportingCode)
|
||||||
alignment: Alignment.centerRight,
|
Align(
|
||||||
child: FilledButton.tonalIcon(
|
alignment: Alignment.centerRight,
|
||||||
style: FilledButton.styleFrom(
|
child: FilledButton.tonalIcon(
|
||||||
padding: kPh12,
|
style: FilledButton.styleFrom(
|
||||||
minimumSize: const Size(44, 44),
|
padding: kPh12,
|
||||||
),
|
minimumSize: const Size(44, 44),
|
||||||
onPressed: () {
|
),
|
||||||
widget.onNext();
|
onPressed: () {
|
||||||
},
|
widget.onNext();
|
||||||
icon: Icon(
|
},
|
||||||
Icons.generating_tokens,
|
icon: Icon(
|
||||||
),
|
Icons.generating_tokens,
|
||||||
label: const SizedBox(
|
),
|
||||||
child: Text(
|
label: const SizedBox(
|
||||||
"Make Modifications",
|
child: Text(
|
||||||
|
"Make Modifications",
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user