Created
June 11, 2019 09:21
-
-
Save mrukhlov/0d8f40b796d814da3a198d8f2618330c to your computer and use it in GitHub Desktop.
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 characters
| 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); | |
| }, | |
| ); | |
| }, | |
| ); | |
| }, | |
| ), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment