Created
June 11, 2019 09:20
-
-
Save mrukhlov/6c39367a84881b4bd0c252a0191949f5 to your computer and use it in GitHub Desktop.
Revisions
-
mrukhlov created this gist
Jun 11, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,117 @@ class TodoCard extends StatelessWidget { final String task; final String type; final bool isCompleted; final Function delete; final Function toggleIsCompleted; const TodoCard( {Key key, this.task, this.type, this.isCompleted, this.delete, this.toggleIsCompleted}) : super(key: key); @override Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.only(left: 12.0, right: 12.0, top: 8.0), child: InkWell( onTap: () { // toggleIsCompleted(); print(type); }, child: Card( child: ListTile( contentPadding: EdgeInsets.all(0), title: Text(task, style: TextStyle( decoration: isCompleted ? TextDecoration.lineThrough : TextDecoration.none)), leading: Padding( padding: const EdgeInsets.only(left: 18.0), child: Icon(!isCompleted ? Icons.radio_button_unchecked : Icons.radio_button_checked)), trailing: InkWell( onTap: () { // delete(); print('delete'); }, child: Container( decoration: BoxDecoration( border: Border(left: BorderSide(color: Colors.grey))), width: 60, height: double.infinity, child: Icon(Icons.delete)), ), ), ), ), ); } } class TodoApp extends StatelessWidget { GraphQLClient client; final TextEditingController controller = new TextEditingController(); initMethod(context) { client = GraphQLProvider.of(context).value; } @override Widget build(BuildContext context) { WidgetsBinding.instance.addPostFrameCallback((_) => initMethod(context)); return Scaffold( appBar: AppBar( centerTitle: true, title: Text("Music List"), ), body: Center( child: Query( options: QueryOptions(document: fetchQuery(), pollInterval: 1), builder: (QueryResult result, {VoidCallback refetch}) { // test = GraphQLProvider.of(context).value; if (result.errors != null) { return Text(result.errors.toString()); } if (result.loading) { return Text('Loading'); } // print(result.data); return ListView.builder( itemCount: result.data["places"].length, itemBuilder: (BuildContext context, int index) { return TodoCard( key: UniqueKey(), task: result.data["places"][index]["name"], type: result.data["places"][index]["type"], isCompleted: false, delete: () async { final Map<String, dynamic> response = (await client.mutate( MutationOptions( document: deleteTaskMutation(result, index), ), )) .data; print(response); }, toggleIsCompleted: () async { final Map<String, dynamic> response = (await client.mutate( MutationOptions( document: toggleIsCompletedMutation(result, index)), )) .data; print(response); }, ); }, ); }, ), ), ); } }