@@ -41,6 +41,9 @@ class _UsersPageState extends State<UsersPage> {
4141 List hobbiesIDsToDelete = [];
4242 List postsIDsToDelete = [];
4343
44+ bool _isRemoveHobbies = false ;
45+ bool _isRemovePosts = false ;
46+
4447 @override
4548 Widget build (BuildContext context) {
4649 return Query (
@@ -133,21 +136,57 @@ class _UsersPageState extends State<UsersPage> {
133136 for (var i = 0 ; i < user["posts" ].length; i++ ){
134137 postsIDsToDelete.add (user["hobbies" ][i]["id" ]);
135138 }
136- debugPrint ("+++${user ["name" ]} Hobbies to delete ${hobbiesIDsToDelete .toString ()}" );
137- debugPrint ("+++${user ["name" ]} Posts to delete ${postsIDsToDelete .toString ()}" );
139+ // debugPrint("+++${user["name"]} Hobbies to delete ${hobbiesIDsToDelete.toString()}");
140+ // debugPrint("+++${user["name"]} Posts to delete ${postsIDsToDelete.toString()}");
141+
142+ setState ((){
143+ _isRemoveHobbies = true ;
144+ _isRemovePosts = true ;
145+ });
138146
139- // runMutation({"id": user["id"]});
140- // Navigator.pushAndRemoveUntil(
141- // context,
142- // MaterialPageRoute(builder: (context){
143- // return const HomeScreen();
144- // },
145- // ), (route) => false,);
147+ runMutation ({"id" : user["id" ]});
148+ Navigator .pushAndRemoveUntil (
149+ context,
150+ MaterialPageRoute (builder: (context){
151+ return const HomeScreen ();
152+ },
153+ ), (route) => false ,);
146154 },
147- );
148- }
155+ );
156+ },
149157 ),
150158 ),
159+ _isRemoveHobbies
160+ ? Mutation (
161+ options: MutationOptions (
162+ document: gql (removeHobbies ()),
163+ onCompleted: (data) {},
164+ ),
165+ builder: (runMutation, result) {
166+ if (hobbiesIDsToDelete.isNotEmpty){
167+ debugPrint ("Calling deleteHobbies" );
168+ runMutation ({
169+ 'ids' : hobbiesIDsToDelete
170+ });
171+ }
172+ return Container ();
173+ },
174+ ) : Container (),
175+ _isRemovePosts
176+ ? Mutation (
177+ options: MutationOptions (
178+ document: gql (removePosts ()),
179+ onCompleted: (data){},
180+ ),
181+ builder: (runMutation, result){
182+ if (postsIDsToDelete.isNotEmpty){
183+ runMutation ({
184+ "ids" : postsIDsToDelete
185+ });
186+ }
187+ return Container ();
188+ },
189+ ) : Container (),
151190 ],
152191 )
153192 ],
@@ -197,4 +236,24 @@ class _UsersPageState extends State<UsersPage> {
197236 }
198237 """ ;
199238 }
239+
240+ String removeHobbies () {
241+ return """
242+ mutation RemoveHobbies(\$ ids: [String]){
243+ RemoveHobbies(ids: \$ ids){
244+
245+ }
246+ }
247+ """ ;
248+ }
249+
250+ String removePosts () {
251+ return """
252+ mutation RemovePosts(\$ ids: [String]){
253+ RemovePosts(ids: \$ ids){
254+
255+ }
256+ }
257+ """ ;
258+ }
200259}
0 commit comments