Created
July 24, 2022 04:06
-
-
Save nextdev1111/da1e5299422454d4b9c19390b9aedd50 to your computer and use it in GitHub Desktop.
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
import 'package:flutter/material.dart'; | |
import 'package:flutter_supabase_yt_1/models/models.dart'; | |
import 'package:flutter_supabase_yt_1/utils/utils.dart'; | |
import 'package:supabase_flutter/supabase_flutter.dart'; | |
class CreateScreen extends StatefulWidget { | |
const CreateScreen({Key? key}) : super(key: key); | |
@override | |
State<CreateScreen> createState() => _CreateScreenState(); | |
} | |
class _CreateScreenState extends State<CreateScreen> { | |
TextEditingController todoController = TextEditingController(); | |
// instance | |
SupabaseDataManager supabaseDataManager = SupabaseDataManager(); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: const Text('Create')), | |
body: Padding( | |
padding: const EdgeInsets.all(20), | |
child: Form( | |
child: Column( | |
children: [ | |
TextFormField( | |
// controller | |
controller: todoController, | |
decoration: const InputDecoration(hintText: 'Todo'), | |
), | |
ElevatedButton(onPressed: _createdData, child: const Text('Create')) | |
], | |
)), | |
), | |
); | |
} | |
Future _createdData() async { | |
Todo todo = Todo(title: todoController.text); | |
PostgrestResponse<dynamic> res = await supabaseDataManager.createData(todo); | |
if (res.error != null) { | |
// ignore: use_build_context_synchronously | |
ScaffoldMessenger.of(context) | |
.showSnackBar(SnackBar(content: Text(res.error!.message))); | |
} | |
// ignore: use_build_context_synchronously | |
ScaffoldMessenger.of(context) | |
.showSnackBar(SnackBar(content: Text('Created'))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment