Full Admin App:
Add cod to UploadVideoLink.dart file:
import 'dart:convert';
import 'dart:math';
import 'package:admin_app_for_code/StoreData/Decoration.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/material.dart';
final fb = FirebaseDatabase.instance.reference();
class UploadYoutubeLink extends StatefulWidget {
@override
_UploadYoutubeLinkState createState() => _UploadYoutubeLinkState();
}
String dropdownValue="C";
String topic,link;
List array = [
'C',"C++","Python","Android","Flutter",
] ;
class _UploadYoutubeLinkState extends State {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Add Youtube Links"),
backgroundColor: Colors.purple,
),
body: Padding(
padding: const EdgeInsets.all(15),
child: Container(
child: Column(
children:[
Text(
"Select Field",
style: TextStyle(
color: Colors.purple,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 10),
DropdownButton(
value: dropdownValue,
icon: Icon(Icons.arrow_drop_down),
style: TextStyle(color: Colors.red, fontSize: 18),
underline: Container(
height: 2,
width: 300,
color: Colors.deepPurpleAccent,
),
onChanged: (data) {
setState(() {
dropdownValue=data;
});
},
items: array.map>((String value) {
return DropdownMenuItem(
value: value,
child: Text(value),
);
}).toList(),
),
Form(
child: Column(
children:[
TextFormField(
onChanged: (val){
topic=val;
},
decoration: textDecoration.copyWith(hintText: "Enter topic Name"),
),
SizedBox(height: 10),
TextFormField(
onChanged: (val){
link=val;
},
decoration: textDecoration.copyWith(hintText: "Enter Video link"),
),
SizedBox(height: 10),
RaisedButton(
onPressed: (){
dynamic key=CreateCryptoRandomString(32);
fb.child("YoutubeLinks").child(key).set({
"language": dropdownValue,
"link": link,
"topic": topic,
});
},
textColor: Colors.white,
padding: const EdgeInsets.all(0.0),
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors:[
Colors.purple,
Colors.purpleAccent,
Colors.pinkAccent,
],
),
),
padding: const EdgeInsets.all(10.0),
child: const Text(
'Submit',
style: TextStyle(fontSize: 20)
),
),
),
],
),
),
],
),
),
),
);
}
}
String CreateCryptoRandomString([int length = 32]) {
final Random _random = Random.secure();
var values = List.generate(length, (i) => _random.nextInt(256));
return base64Url.encode(values);
}
Welcome to EasyCoding with Ammara
Subscribe My Coding Channel:
https://www.youtube.com/channel/UC8UsfNYmbKiRJvI9ZhhApEw?view_as=subscriber
Subscribe my personal YouTube Channel:
https://www.youtube.com/channel/UCa93R2oNQMuX0fOKa9eV4zg?view_as=subscriber
Let's Start
Add cod to UploadVideoLink.dart file:
import 'dart:convert';
import 'dart:math';
import 'package:admin_app_for_code/StoreData/Decoration.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/material.dart';
final fb = FirebaseDatabase.instance.reference();
class UploadYoutubeLink extends StatefulWidget {
@override
_UploadYoutubeLinkState createState() => _UploadYoutubeLinkState();
}
String dropdownValue="C";
String topic,link;
List
'C',"C++","Python","Android","Flutter",
] ;
class _UploadYoutubeLinkState extends State
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Add Youtube Links"),
backgroundColor: Colors.purple,
),
body: Padding(
padding: const EdgeInsets.all(15),
child: Container(
child: Column(
children:
Text(
"Select Field",
style: TextStyle(
color: Colors.purple,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 10),
DropdownButton
value: dropdownValue,
icon: Icon(Icons.arrow_drop_down),
style: TextStyle(color: Colors.red, fontSize: 18),
underline: Container(
height: 2,
width: 300,
color: Colors.deepPurpleAccent,
),
onChanged: (data) {
setState(() {
dropdownValue=data;
});
},
items: array.map
return DropdownMenuItem
value: value,
child: Text(value),
);
}).toList(),
),
Form(
child: Column(
children:
TextFormField(
onChanged: (val){
topic=val;
},
decoration: textDecoration.copyWith(hintText: "Enter topic Name"),
),
SizedBox(height: 10),
TextFormField(
onChanged: (val){
link=val;
},
decoration: textDecoration.copyWith(hintText: "Enter Video link"),
),
SizedBox(height: 10),
RaisedButton(
onPressed: (){
dynamic key=CreateCryptoRandomString(32);
fb.child("YoutubeLinks").child(key).set({
"language": dropdownValue,
"link": link,
"topic": topic,
});
},
textColor: Colors.white,
padding: const EdgeInsets.all(0.0),
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors:
Colors.purple,
Colors.purpleAccent,
Colors.pinkAccent,
],
),
),
padding: const EdgeInsets.all(10.0),
child: const Text(
'Submit',
style: TextStyle(fontSize: 20)
),
),
),
],
),
),
],
),
),
),
);
}
}
String CreateCryptoRandomString([int length = 32]) {
final Random _random = Random.secure();
var values = List
return base64Url.encode(values);
}
Add code to StoreData.dart file:import 'dart:convert';
import 'dart:io';
import 'dart:math';
import 'package:admin_app_for_code/StoreData/Decoration.dart';
import 'package:admin_app_for_code/StoreData/UploadVideoLink.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flushbar/flushbar.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:path/path.dart' as Path;
final fb = FirebaseDatabase.instance.reference().child("PostData");
File image;
String _uploadedFileURL;
Future getImage() async {
await ImagePicker.pickImage(source: ImageSource.gallery).then((img){
image = img;
});
}
class StorePost extends StatefulWidget {
@override
_StorePostState createState() => _StorePostState();
}
class _StorePostState extends State {
String topic,code,link;
List array = [
'C',"C++","Python","Android","Flutter",
] ;
String dropdownValue = 'C';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.purple,
title: Text("Add New Post"),
actions: [
IconButton(
icon: Icon(Icons.add),
onPressed: (){
Navigator.push(context,
MaterialPageRoute(builder: (context)=>UploadYoutubeLink()));
},
),
],
),
body: Padding(
padding: Const EdgeInsets.all(15),
child: Container(
child: Column(
children: [
DropdownButton(
value: dropdownValue,
onChanged: (String newValue) {
setState(() {
dropdownValue = newValue;
});
},
items: array
.map>((String value) {
return DropdownMenuItem(
value: value,
child: Text(value),
);
}).toList(),
),
SizedBox(height: 10),
Form(
child: Column(
children: [
TextFormField(
onChanged: (val){
topic=val;
},
decoration: textDecoration.copyWith(hintText: "Enter Topic Name"),
),
SizedBox(height: 10),
TextFormField(
keyboardType: TextInputType.multiline,
maxLines: null,
onChanged: (val){
code=val;
},
decoration: textDecoration.copyWith(hintText: "Enter Code"),
),
SizedBox(height: 10),
TextFormField(
onChanged: (val){
link=val;
},
decoration: textDecoration.copyWith(hintText: "Enter Link"),
),
SizedBox(height: 10),
RaisedButton(
onPressed: (){
getImage();
},
textColor: Colors.white,
padding: const EdgeInsets.all(0.0),
child: Container(
padding: const EdgeInsets.all(10.0),
child: const Text(
'Select Image',
style: TextStyle(fontSize: 20)
),
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.purple,
Colors.purpleAccent,
Colors.pinkAccent,
],
),
),
),
),
SizedBox(height: 10),
MaterialButton(
onPressed: () async {
if(topic!=null || code!=null || link!=null || image!=null){
StorageReference storageReference = FirebaseStorage.instance
.ref().child('photo/${Path.basename(image.path)}}');
StorageUploadTask uploadTask = storageReference.putFile(image);
await uploadTask.onComplete;
storageReference.getDownloadURL().then((fileURL) {
_uploadedFileURL = fileURL;
if(_uploadedFileURL!=null){
dynamic key=CreateCryptoRandomString(32);
fb.child(key).set({
"language": dropdownValue,
"topic": topic,
"link": link,
"code": code,
"image": _uploadedFileURL,
});
}
});
}
else{
showInfoFlushbar(context);
}
},
textColor: Colors.white,
padding: const EdgeInsets.all(0.0),
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.purple,
Colors.purpleAccent,
Colors.pinkAccent,
],
),
),
padding: const EdgeInsets.all(10.0),
child: const Text(
'Submit',
style: TextStyle(fontSize: 20)
),
),
),
],
),
)
],
),
),
),
);
}
}
String CreateCryptoRandomString([int length = 32]) {
final Random _random = Random.secure();
var values = List.generate(length, (i) => _random.nextInt(256));
return base64Url.encode(values);
}
void showInfoFlushbar(BuildContext context) {
Flushbar(
title: 'Error Message',
message: 'Field not empty',
icon: Icon(
Icons.info_outline,
size: 28,
color: Colors.blue.shade300,
),
leftBarIndicatorColor: Colors.blue.shade300,
duration: Duration(seconds: 3),
)..show(context);
}
Add code to decoration.dart file.
import 'package:flutter/material.dart';
const textDecoration = InputDecoration(
fillColor: Colors.white,
filled: true,
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.white,
width: 2,
)
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.purple,
width: 2,
)
),
);
Add code to main.dart:
import 'package:admin_app_for_code/StoreData/StorePost.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: StorePost(),
);
}
}
Add depedency to pubspec.yaml file:
firebase_database: ^3.1.1
flushbar: ^1.5.0
image_picker: ^0.6.6+1
firebase_storage: ^3.0.3
Add to build.gradle file:
classpath 'com.google.gms:google-services:4.3.2'
Add code to app=>src=>build.gradle.
apply plugin: 'com.google.gms.google-services'
Watch the video for understand: