Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
vijaycreations

Vijay R vijayinyoutube

:octocat:
vijaycreations
View GitHub Profile
View buildShimmerItems.dart
Widget buildShimmerItems() => ListView.separated(
padding: const EdgeInsets.all(8),
itemCount: 10,
separatorBuilder: (BuildContext context, int index) => const Divider(),
itemBuilder: (BuildContext context, int index) {
return const ShimmerWidget();
});
View home_page.dart
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Firebase Demo"),
),
body: FutureBuilder(
future: FireStoreDataBase().getData(),
builder: (context, snapshot) {
if (snapshot.hasError) {
View shimmer.dart
class ShimmerWidget extends StatelessWidget {
const ShimmerWidget({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 5.00, vertical: 5.00),
child: SizedBox(
child: Shimmer.fromColors(
baseColor: Colors.grey.shade300,
View addField.dart
Future<void> addField() {
return collectionRef
.doc('MyDoc')
//will edit the doc if already available or will create a new doc with this given ID
.set(
{'role': "developer"},
SetOptions(merge: true),
// if set to 'false', then only these given fields will be added to that doc
)
.then((value) => debugPrint("User Added"))
View addStudents.dart
Future<void> addStudents() async {
//creates a new doc with unique doc ID
return collectionRef
.add({
'Name': "TestName",
})
.then((value) => debugPrint("User Added"))
.catchError((error) => debugPrint("Failed to add user: $error"));
}
View buildItems.dart
Widget buildItems(dataList) => ListView.separated(
padding: const EdgeInsets.all(8),
itemCount: dataList.length,
separatorBuilder: (BuildContext context, int index) => const Divider(),
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text(
dataList[index]["Name"],
),
subtitle: Text(dataList[index]["Dept"]),
View homepage.dart
FutureBuilder(
future: FireStoreDataBase().getData(),
builder: (context, snapshot) {
if (snapshot.hasError) {
return const Text(
"Something went wrong",
);
}
if (snapshot.connectionState == ConnectionState.done) {
dataList = snapshot.data as List;
View firebase.dart
class FireStoreDataBase {
List studentsList = [];
final CollectionReference collectionRef =
FirebaseFirestore.instance.collection("Students");
Future getData() async {
try {
//to get data from a single/particular document alone.
// var temp = await collectionRef.doc("<your document ID here>").get();
View index.html
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js"></script>
<script>
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: "",
authDomain: "",
projectId: "",
View encrypt.dart
performEncryption(response) async {
var encrypted = encryption.encryptMsg(response.toString()).base16;
print(encrypted);
var decrypted = encryption.decryptMsg(encryption.getCode(encrypted));
print(decrypted);
final data1 = await json.decode(decrypted);
setState(() {
accounts = data1["account"];
});