Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:cloud_firestore/cloud_firestore.dart';
- import 'package:firebaser/student.dart';
- import 'package:flutter/material.dart';
- import 'package:firebase_core/firebase_core.dart';
- import 'package:firebaser/firebase_options.dart';
- void main() async {
- WidgetsFlutterBinding.ensureInitialized();
- await Firebase.initializeApp(
- options: DefaultFirebaseOptions.currentPlatform,
- );
- runApp(MaterialApp(
- theme: ThemeData(
- brightness: Brightness.light,
- primaryColor: Colors.blue,
- colorScheme: ColorScheme.fromSwatch().copyWith(secondary: Colors.cyan),
- ),
- home: MyApp(),
- ));
- }
- class MyApp extends StatefulWidget {
- const MyApp({super.key});
- @override
- State<MyApp> createState() => _MyAppState();
- }
- class _MyAppState extends State<MyApp> {
- TextEditingController ct1 = new TextEditingController();
- TextEditingController ct2 = new TextEditingController();
- TextEditingController ct3 = new TextEditingController();
- TextEditingController ct4 = new TextEditingController();
- CollectionReference cref = FirebaseFirestore.instance.collection("Students");
- void enterData(TextEditingController ct1, TextEditingController ct2,
- TextEditingController ct3, TextEditingController ct4) {
- String n = ct1.text;
- String i = ct2.text;
- String c = ct3.text;
- double g = double.parse(ct4.text);
- Map<String, dynamic> map = {
- "Name": n,
- "ID": i,
- "Course": c,
- "GPA": g,
- };
- cref
- .add(map)
- .then((value) => print("User added"))
- .catchError((error) => print("Errrrrrrrrrr "));
- }
- void getData(String doc, TextEditingController ct1, TextEditingController ct2,
- TextEditingController ct3, TextEditingController ct4) {
- cref.doc(doc).get().then((value) {
- dynamic obj = value.data();
- print(obj["Name"]);
- print(obj["Course"]);
- print(obj["ID"]);
- print(obj["GPA"]);
- });
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: const Text("Airbase inc."),
- ),
- body: Column(
- children: <Widget>[
- Padding(
- padding: const EdgeInsets.all(8.0),
- child: TextFormField(
- controller: ct1,
- decoration: const InputDecoration(
- labelText: "Student Name",
- fillColor: Colors.white,
- focusedBorder: OutlineInputBorder(
- borderSide: BorderSide(color: Colors.blue, width: 2.0))),
- onChanged: (String str) {},
- ),
- ),
- Padding(
- padding: const EdgeInsets.all(8.0),
- child: TextFormField(
- controller: ct2,
- decoration: const InputDecoration(
- labelText: "Student ID",
- fillColor: Colors.white,
- focusedBorder: OutlineInputBorder(
- borderSide: BorderSide(color: Colors.blue, width: 2.0))),
- onChanged: (String str) {},
- ),
- ), //
- Padding(
- padding: const EdgeInsets.all(8.0),
- child: TextFormField(
- controller: ct3,
- decoration: const InputDecoration(
- labelText: "Course",
- fillColor: Colors.white,
- focusedBorder: OutlineInputBorder(
- borderSide: BorderSide(color: Colors.blue, width: 2.0))),
- onChanged: (String str) {},
- ),
- ),
- Padding(
- padding: const EdgeInsets.all(8.0),
- child: TextFormField(
- controller: ct4,
- decoration: const InputDecoration(
- labelText: "GPA",
- fillColor: Colors.white,
- focusedBorder: OutlineInputBorder(
- borderSide: BorderSide(color: Colors.blue, width: 2.0))),
- onChanged: (String str) {},
- ),
- ), //
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- ElevatedButton(
- onPressed: () {
- // enterData(ct1, ct2, ct3, ct4);
- getData("cTohq82nNzzrmzc32KR7", ct1, ct2, ct3, ct4);
- },
- child: Icon(Icons.memory_sharp),
- )
- ],
- )
- ],
- ),
- );
- }
- }
Add Comment
Please, Sign In to add comment