Flutter

final ref = FirebaseDatabase.instance.reference();

 void getData() {
    ref
        .child('videos')
        .child('class_10')
        .child('chapter_1')
        .once()
        .then((DataSnapshot data) {
      print(data.value);
      print(data.key);
    });
  }
  
    void createRecord() {
    ref
        .child('videos')
        .child('class_10')
        .child('chapter_1')
        .set([
      {"length": "1:3333", "title": "Introduction 1.1"},
      {"length": "2:30", "title": "Introduction 1.2"}
    ]);
  }
   final databaseReference = Firestore.instance;

 
 void createRecord() async {
    Map data = {'length': '1:30:20', 'position': '1', 'title': 'Introduction 3.'};
    await databaseReference
        .collection("class_10")
        .document('chapter_4')
        .collection('videos')
        .document()
        .setData(
           data
);

//    await databaseReference.collection("classes")
//        .document('10')
//        .collection('chapter')
//        .document('1')
//    .collection('videos')
//    .document('1')
//        .setData({
//      'title': 'Introduction 1 Sets',
//      'length': '10:20'
//    });
  }

  void getData() {
    databaseReference
        .collection("class_10")
        .document('chapter_1')
        .collection('videos')
        .getDocuments()
        .then((QuerySnapshot snapshot) {
      snapshot.documents.forEach((f) => print('${f.data}}'));
    });
  }

  void updateData() {
    try {
      databaseReference
          .collection('books')
          .document('1')
          .updateData({'description': 'Head First Flutter'});
    } catch (e) {
      print(e.toString());
    }
    databaseReference
        .collection("classes")
        .document('10')
        .collection('chapter')
        .document('1')
        .collection('videos');
  }

  void deleteData() {
    try {
      databaseReference.collection('books').document('1').delete();
    } catch (e) {
      print(e.toString());
    }
  }
import 'package:dynamicmathapp/services/auth.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:dynamicmathapp/models/user.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class Home extends StatelessWidget {
  final AuthService _auth = AuthService();
  final ref = FirebaseDatabase.instance.reference();

  @override
  Widget build(BuildContext context) {
    User user = Provider.of<User>(context);

    return Scaffold(
      backgroundColor: Colors.brown[50],
      appBar: AppBar(
        title: Text('Welcome'),
        backgroundColor: Colors.brown[400],
        elevation: 0.0,
        actions: <Widget>[
          FlatButton.icon(
            icon: Icon(Icons.person),
            label: Text('logout'),
            onPressed: () async {
              await _auth.signOut();
            },
          ),
        ],
      ),
      body: Column(
        children: <Widget>[
          Container(
            child: Text(
              'ID:' + user.uid + 'email:' + user.email,
            ),
          ),
          RaisedButton(
            child: Text('Create Record'),
            onPressed: () {
              createRecord();
            },
          ),
          RaisedButton(
            child: Text('View Record'),
            onPressed: () {
              getData();
            },
          ),
          RaisedButton(
            child: Text('Update Record'),
            onPressed: () {
              updateData();
            },
          ),
          RaisedButton(
            child: Text('Delete Record'),
            onPressed: () {
              deleteData();
            },
          ),
        ],
      ),
    );
  }

  void createRecord() {
    ref
        .child('videos')
        .child('class_10')
        .child('chapter_1')
        .set([
      {"length": "1:3333", "title": "Introduction 1.1"},
      {"length": "2:30", "title": "Introduction 1.2"}
    ]);
  }

  void getData() {
    ref
        .child('videos')
        .child('class_10')
        .child('chapter_1')
        .once()
        .then((DataSnapshot data) {
      print(data..value);
      print(data.key);
    });
  }

  void updateData() {}

  void deleteData() {}
}
//Inside main.dart
return MaterialApp(
 initialRoute: WelcomeScreen.id,
 routes: {
   WelcomeScreen.id: (context) => WelcomeScreen(),
   LoginScreen.id: (context) => LoginScreen(),
   RegistrationScreen.id: (context) => RegistrationScreen(),
   ChatScreen.id: (context) => ChatScreen(),
 },
);

//Inside **** Class:
static const String id = '****';

//Inside onPressed
  onTap: () => Navigator.pushNamed(context, VideoScreen.id, arguments: {
                'chapter_name': 'Chapter $index',
              }),
              
 // In receiving side
 final  Map<String, String> received = ModalRoute.of(context).settings.arguments;
    final chapterName = received['chapter_name'];
 
main() {
  List customers = [];
  customers.add(Customer('Jack', 23));
  customers.add(Customer('Adam', 27));
  customers.add(Customer('Katherin', 25));

  customers.sort((a, b) => a.age.compareTo(b.age));
  print('Sort by Age: ' + customers.toString());

  customers.sort((a, b) => a.name.compareTo(b.name));
  print('Sort by Name: ' + customers.toString());
}
Center(
          child: new Container(
            padding: const EdgeInsets.all(8.0),
            height: 500.0,
            width: 500.0,
            child: new Stack(
              overflow: Overflow.visible,
              children: <Widget>[
                new Icon(Icons.pages, size: 36.0, color: Colors.red),
                new Positioned(
                  left: 20.0,
                  child: new Icon(Icons.pages, size: 36.0, color: Colors.green),
                ),
 
              ],
            ),
          ),
    )
Text('Click \u{2795} to add')
RichText( text: TextSpan( children: [ TextSpan( text: "Click ", ), WidgetSpan( child: Icon(Icons.add, size: 14), ), TextSpan( text: " to add", ), ], ), )
Widget _signInButton() {




   return OutlineButton(


     splashColor: Colors.grey,


     onPressed: () {},


     shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)),


     highlightElevation: 0,


     borderSide: BorderSide(color: Colors.grey),


     child: Padding(


       padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),


       child: Row(


         mainAxisSize: MainAxisSize.min,


         mainAxisAlignment: MainAxisAlignment.center,


         children: <Widget>[


           Image(image: AssetImage("assets/google_logo.png"), height: 35.0),


           Padding(


             padding: const EdgeInsets.only(left: 10),


             child: Text(


               'Sign in with Google',


               style: TextStyle(


                 fontSize: 20,


                 color: Colors.grey,


               ),


             ),


           )


         ],


       ),


     ),


   );


 }


Similiar Collections