Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobaraujo7 committed Jul 19, 2024
1 parent fad6ab0 commit 5f61a1b
Show file tree
Hide file tree
Showing 13 changed files with 261 additions and 186 deletions.
4 changes: 2 additions & 2 deletions doc/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,79 @@ class CommandsPage extends StatefulWidget {
}

class _CommandsPageState extends State<CommandsPage> {
void _createCommand() {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('Create command'),
content: const Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('data'),
SizedBox(height: 10),
TextField(
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Name',
),
),
SizedBox(height: 10),
TextField(
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Name',
),
maxLines: 3,
),
],
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('Cancel'),
),
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('Save'),
),
],
);
},
);
}

void _confirmDelete() {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('Delete command'),
content: const Text('Are you sure you want to delete this command?'),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('Cancel'),
),
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('Delete'),
),
],
);
},
);
}

@override
Widget build(BuildContext context) {
return CommandScaffold(
Expand All @@ -40,13 +113,21 @@ class _CommandsPageState extends State<CommandsPage> {
CommandTile(
title: 'Command 1',
icon: Icons.ac_unit,
actions: const ['Edit', 'Delete'],
onAction: (action) {
_confirmDelete();
},
onLongPress: () {
Routefly.push(routePaths.home.editCommand);
},
),
CommandTile(
title: 'Command 2',
icon: Icons.access_alarm,
actions: const ['Edit', 'Delete'],
onAction: (action) {
_createCommand();
},
onLongPress: () {
Routefly.push(routePaths.home.editCommand);
},
Expand Down
10 changes: 10 additions & 0 deletions example/command_hub/apps/mobile/lib/app/(public)/home_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:flutter/material.dart';

class HomePage extends StatelessWidget {
const HomePage({super.key});

@override
Widget build(BuildContext context) {
return const Placeholder();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ library core_module;

export 'package:routefly/routefly.dart';

export 'src/agent.dart';
export 'src/pipeline.dart';
export 'src/command.dart';
96 changes: 0 additions & 96 deletions example/command_hub/packages/core_module/lib/src/agent.dart

This file was deleted.

58 changes: 58 additions & 0 deletions example/command_hub/packages/core_module/lib/src/command.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'dart:convert';

import 'symbol_icon.dart';

class Command {
final String name;
final SymbolIcon icon;
final String prompt;

Command({
required this.icon,
required this.name,
required this.prompt,
});

@override
bool operator ==(covariant Command other) {
if (identical(this, other)) return true;

return other.name == name && other.icon == icon && other.prompt == prompt;
}

@override
int get hashCode => name.hashCode ^ icon.hashCode ^ prompt.hashCode;

Map<String, dynamic> toMap() {
return <String, dynamic>{
'name': name,
'icon': icon.name,
'prompt': prompt,
};
}

factory Command.fromMap(Map<String, dynamic> map) {
return Command(
name: map['name'] as String,
icon: SymbolIcon.fromString(map['icon'] as String),
prompt: map['prompt'] as String,
);
}

String toJson() => json.encode(toMap());

factory Command.fromJson(String source) => Command.fromMap(json.decode(source) as Map<String, dynamic>);

Command copyWith({
String? name,
SymbolIcon? icon,
String? prompt,
}) {
return Command(
name: name ?? this.name,
icon: icon ?? this.icon,
prompt: prompt ?? this.prompt,
);
}
}
29 changes: 0 additions & 29 deletions example/command_hub/packages/core_module/lib/src/pipeline.dart

This file was deleted.

17 changes: 17 additions & 0 deletions example/command_hub/packages/core_module/lib/src/symbol_icon.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:flutter/material.dart';

enum SymbolIcon {
home(Icons.home);

// constructor
final IconData data;
const SymbolIcon(this.data);

// adapters
static SymbolIcon fromString(String value) {
return SymbolIcon.values.firstWhere(
(e) => e.name == value,
orElse: () => SymbolIcon.home,
);
}
}
Loading

0 comments on commit 5f61a1b

Please sign in to comment.