mirror of
https://github.com/foss42/apidash.git
synced 2025-07-02 22:16:44 +08:00
update widgets
This commit is contained in:
38
lib/widgets/button_learn.dart
Normal file
38
lib/widgets/button_learn.dart
Normal file
@ -0,0 +1,38 @@
|
||||
import 'package:apidash_design_system/apidash_design_system.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class LearnButton extends StatelessWidget {
|
||||
const LearnButton({
|
||||
super.key,
|
||||
this.label,
|
||||
this.icon,
|
||||
this.url,
|
||||
});
|
||||
|
||||
final String? label;
|
||||
final IconData? icon;
|
||||
final String? url;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var textLabel = label ?? 'Learn';
|
||||
return SizedBox(
|
||||
height: 24,
|
||||
child: ADFilledButton(
|
||||
icon: Icons.help,
|
||||
iconSize: kButtonIconSizeSmall,
|
||||
label: textLabel,
|
||||
isTonal: true,
|
||||
buttonStyle: ButtonStyle(
|
||||
padding: WidgetStatePropertyAll(kP10),
|
||||
),
|
||||
onPressed: () {
|
||||
if (url != null) {
|
||||
launchUrl(Uri.parse(url!));
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
53
lib/widgets/editor_code.dart
Normal file
53
lib/widgets/editor_code.dart
Normal file
@ -0,0 +1,53 @@
|
||||
import 'package:apidash/providers/settings_providers.dart';
|
||||
import 'package:apidash_design_system/apidash_design_system.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_code_editor/flutter_code_editor.dart';
|
||||
import 'package:flutter_highlight/themes/monokai.dart';
|
||||
import 'package:flutter_highlight/themes/xcode.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
class CodeEditor extends ConsumerWidget {
|
||||
final bool readOnly;
|
||||
final CodeController controller;
|
||||
const CodeEditor({
|
||||
super.key,
|
||||
required this.controller,
|
||||
this.readOnly = false,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final settings = ref.watch(settingsProvider);
|
||||
return CodeTheme(
|
||||
data: CodeThemeData(
|
||||
styles: settings.isDark ? monokaiTheme : xcodeTheme,
|
||||
),
|
||||
child: CodeField(
|
||||
expands: true,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: kBorderRadius8,
|
||||
border: BoxBorder.all(
|
||||
color: Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
),
|
||||
color: Theme.of(context).colorScheme.surfaceContainerLowest,
|
||||
),
|
||||
readOnly: readOnly,
|
||||
smartDashesType: SmartDashesType.enabled,
|
||||
smartQuotesType: SmartQuotesType.enabled,
|
||||
background: Theme.of(context).colorScheme.surfaceContainerLowest,
|
||||
gutterStyle: GutterStyle(
|
||||
width: 0, // TODO: Fix numbers size
|
||||
margin: 2,
|
||||
textAlign: TextAlign.left,
|
||||
showFoldingHandles: false,
|
||||
showLineNumbers: false,
|
||||
),
|
||||
cursorColor: Theme.of(context).colorScheme.primary,
|
||||
controller: controller,
|
||||
textStyle: kCodeStyle.copyWith(
|
||||
fontSize: Theme.of(context).textTheme.bodyMedium?.fontSize,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
import 'package:apidash/providers/settings_providers.dart';
|
||||
import 'package:apidash_design_system/apidash_design_system.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_code_editor/flutter_code_editor.dart';
|
||||
import 'package:flutter_highlight/themes/monokai.dart';
|
||||
import 'package:flutter_highlight/themes/xcode.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
class ScriptsEditorPane extends ConsumerStatefulWidget {
|
||||
final bool readOnly;
|
||||
final CodeController controller;
|
||||
const ScriptsEditorPane({
|
||||
super.key,
|
||||
required this.controller,
|
||||
this.readOnly = false,
|
||||
});
|
||||
|
||||
@override
|
||||
ConsumerState<ScriptsEditorPane> createState() => _ScriptsEditorPaneState();
|
||||
}
|
||||
|
||||
class _ScriptsEditorPaneState extends ConsumerState<ScriptsEditorPane> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final settings = ref.watch(settingsProvider);
|
||||
return Padding(
|
||||
padding: kPt5o10,
|
||||
child: CodeTheme(
|
||||
data: CodeThemeData(
|
||||
styles: settings.isDark ? monokaiTheme : xcodeTheme,
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
child: CodeField(
|
||||
minLines: 35,
|
||||
readOnly: widget.readOnly,
|
||||
smartDashesType: SmartDashesType.enabled,
|
||||
smartQuotesType: SmartQuotesType.enabled,
|
||||
background: Theme.of(context).colorScheme.surfaceContainerLowest,
|
||||
gutterStyle: GutterStyle(
|
||||
width: 40, // TODO: Fix numbers size
|
||||
margin: 2,
|
||||
textAlign: TextAlign.left,
|
||||
showFoldingHandles: false,
|
||||
showLineNumbers: false,
|
||||
),
|
||||
cursorColor: Theme.of(context).colorScheme.primary,
|
||||
controller: widget.controller,
|
||||
textStyle: kCodeStyle.copyWith(
|
||||
fontSize: Theme.of(context).textTheme.bodyMedium?.fontSize,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(9),
|
||||
border: Border.all(
|
||||
color: Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
),
|
||||
color: Theme.of(context).colorScheme.surfaceContainerLowest,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ export 'button_copy.dart';
|
||||
export 'button_discord.dart';
|
||||
export 'button_form_data_file.dart';
|
||||
export 'button_group_filled.dart';
|
||||
export 'button_learn.dart';
|
||||
export 'button_repo.dart';
|
||||
export 'button_save_download.dart';
|
||||
export 'button_send.dart';
|
||||
@ -23,6 +24,7 @@ export 'dropdown_content_type.dart';
|
||||
export 'dropdown_formdata.dart';
|
||||
export 'dropdown_http_method.dart';
|
||||
export 'dropdown_import_format.dart';
|
||||
export 'editor_code.dart';
|
||||
export 'editor_json.dart';
|
||||
export 'editor.dart';
|
||||
export 'error_message.dart';
|
||||
|
Reference in New Issue
Block a user