Skip to content

Commit

Permalink
fix remote not updating after edited
Browse files Browse the repository at this point in the history
  • Loading branch information
TalkingPanda0 committed Feb 19, 2024
1 parent 4e835dd commit 73b7a64
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 33 deletions.
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/material.dart';
import 'package:osram_controller/utils/ir.dart';
import 'package:osram_controller/utils/remote.dart';
import 'package:osram_controller/widgets/remote_view.dart';

Expand Down
42 changes: 23 additions & 19 deletions lib/widgets/create_remote.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ class _CreateRemoteState extends State<CreateRemote> {
)
: TextButton(
onLongPress: () {
remote.buttons.removeAt(index);
setState(() {
remote.buttons.removeAt(index);
});
},
onPressed: () async {
try {
Expand All @@ -105,25 +107,27 @@ class _CreateRemoteState extends State<CreateRemote> {
child: Text(button.image),
);
} else {
return ElevatedButton(
child: const Icon(Icons.add),
onPressed: () async {
try {
IRButton button = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const CreateButton(),
));
return Padding(
padding: EdgeInsets.all(8),
child: ElevatedButton(
child: const Icon(Icons.add),
onPressed: () async {
try {
IRButton button = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const CreateButton(),
));

setState(() {
remote.buttons.add(button);
});
} catch (e) {
print(e);
return;
}
},
);
setState(() {
remote.buttons.add(button);
});
} catch (e) {
print(e);
return;
}
},
));
}
},
),
Expand Down
31 changes: 17 additions & 14 deletions lib/widgets/remote_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,25 @@ class _RemoteListState extends State<RemoteList> {
return Card(
key: Key(index.toString()),
child: ListTile(
// Add a icon button to remove the remote
trailing: Wrap(children: [
IconButton(
icon: const Icon(Icons.edit),
onPressed: () {
setState(() {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CreateRemote(
remote: remotes[index],
),
));
});
},
),
icon: const Icon(Icons.edit),
onPressed: () async {
try {
Remote remote = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CreateRemote(
remote: remotes[index],
),
));
setState(() {
remotes[index] = remote;
});
} catch (e) {
return;
}
}),
IconButton(
icon: const Icon(Icons.delete),
onPressed: () {
Expand Down

0 comments on commit 73b7a64

Please sign in to comment.