-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from flame-engine/luan.rename
Add rename feature to fire-atlas
- Loading branch information
Showing
3 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
fire_atlas_editor/lib/screens/editor_screen/widgets/rename_atlas_modal.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import 'package:fire_atlas_editor/store/actions/atlas_actions.dart'; | ||
import 'package:fire_atlas_editor/store/actions/editor_actions.dart'; | ||
import 'package:fire_atlas_editor/store/store.dart'; | ||
import 'package:fire_atlas_editor/widgets/button.dart'; | ||
import 'package:fire_atlas_editor/widgets/input_text_row.dart'; | ||
import 'package:fire_atlas_editor/widgets/text.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:slices/slices.dart'; | ||
|
||
class RenameAtlasModal extends StatefulWidget { | ||
final String? currentName; | ||
|
||
const RenameAtlasModal({Key? key, required this.currentName}) | ||
: super(key: key); | ||
|
||
@override | ||
State createState() => _RenameAtlasModalState(); | ||
} | ||
|
||
class _RenameAtlasModalState extends State<RenameAtlasModal> { | ||
final newNameController = TextEditingController(); | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
newNameController.text = widget.currentName ?? ''; | ||
} | ||
|
||
@override | ||
Widget build(BuildContext ctx) { | ||
return Container( | ||
padding: const EdgeInsets.only(left: 20, right: 20), | ||
child: Column( | ||
children: [ | ||
const FSubtitleTitle(title: 'Rename atlas'), | ||
InputTextRow( | ||
label: 'New name:', | ||
inputController: newNameController, | ||
), | ||
const SizedBox(height: 10), | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
FButton( | ||
label: 'Cancel', | ||
onSelect: () => _closeModal(ctx), | ||
), | ||
const SizedBox(width: 20), | ||
FButton( | ||
label: 'Rename', | ||
onSelect: () => _renameAtlas(ctx), | ||
), | ||
], | ||
), | ||
const SizedBox(height: 20), | ||
], | ||
), | ||
); | ||
} | ||
|
||
Future<void> _renameAtlas(BuildContext ctx) async { | ||
final store = SlicesProvider.of<FireAtlasState>(ctx); | ||
final newName = newNameController.text; | ||
if (newName.isEmpty) { | ||
store.dispatch( | ||
CreateMessageAction( | ||
type: MessageType.ERROR, | ||
message: 'The new name is required.', | ||
), | ||
); | ||
} else { | ||
final action = RenameAtlasAction(newAtlasId: newName); | ||
await store.dispatchAsync(action); | ||
await _closeModal(ctx); | ||
} | ||
} | ||
|
||
Future<void> _closeModal(BuildContext ctx) async { | ||
final store = SlicesProvider.of<FireAtlasState>(ctx); | ||
store.dispatch(CloseEditorModal()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters