xmodels 0.0.1
xmodels: ^0.0.1 copied to clipboard
This is a flutter package that help developers to create and develop Mobile, web and desktop apps fast and affectively. By the help of XModel you just have to create class and you have to extend it to [...]
XModel Documentation #
This is a flutter package that help developers to create and develop Mobile, web and desktop apps fast and affectively. By the help of XModel you just have to create class and you have to extend it to XModel class. It will then give you all the functions that you will need to develop your projects. It is specially developed to work with firebase.
Usage #
- Connect your project with firebase as usual.
- Initialize firebase App. Now you are good to go.
To create user #
Firstly create class for user.
import 'package:xmodels/xuser.dart';
class Auth extends XUser {
@override
///You can specify the required fields in "fields" which will takes list of fields. And also make sure to pass id (autoIncrement)..
Xfields fields = [
DataType('id', fieldtype: Dtype.autoIncrement),
DataType('name'),
];
}
final auth = Auth();
final email = TextEditingController();
final pass = TextEditingController();
final name = TextEditingController();
void signup(){
auth.createUser(email: email.text,password: pass.text, fieldsExtention: {'name': name.text,})
///"fieldsExtention" is where you pass the extra fields that you declared in Auth class in fields.
}
Now it will automatically creates collections in firebase for users data and register user in authentication.
##Check if user is already logged in
StreamBuilder(
stream: XUser.authStateChanges,
builder: (context, snapshot) {
return snapshot.connectionState == ConnectionState.active
? snapshot.data != null
? const MyHomePage(title: 'Flutter App.')
: const Login()
: const Loader();
});
User login #
void login(){
auth.signIn(email: email.text, password: pass.text);
}
Get User Data #
final userData = await xCurrentuser();
To create new Models #
class Group extends XModel {
Group() : super('Group'); ///Here you have to pass model name in string. It will be your collection name in Firebase Firestore.
@override
Xfields fields = [
DataType('id', fieldtype: Dtype.autoIncrement),
DataType('name'),
];
///fields is where you specify requierd field for this model. And also make sure to pass id (autoIncrement).
}
To add data to Model #
final user = Group(); //create object of the class
void add(){
user.add({'name': 'Codectionary'})
// data must have all the fileds metioned in class fields. If you want to put null as the value of the field, you can simply pass null.
}
To delete data from Model #
final user = Group(); //create object of the class
void delete(){
user.delete('id', data[index].data['id']);
// field is the key and value is the value. it will compare and it will delete that data which meet the condition.
//you can check any of your keys and values.
}
To Update data of Model #
final user = Group(); //create object of the class
void update(){
user.update('id', data[index].data['id'], {'name': 'Flutter'});
// field is the key and value is the value. it will compare and it will update its data with given data.
//you can check any of your keys and values.
}
To Delete All data from Model #
final user = Group(); //create object of the class
void delete(){
user.deleteAll()
}
Get data from models #
final user = Group(); //create object of the class
void getData(){
user.get(key, value) /// here you have to pass key and value to compare. It will get you only one data which meets the codition.
}
Get data array from models #
final user = Group(); //create object of the class
void getData(){
user.filter() /// this will give you array of the data. you can also compare by passing key and value which are optional.
}
Get data Stream #
StreamBuilder builder = user.xStreambuilder((context, List<XDataModel>? data){
return Container();
}
//return you a steam builder.
Get automatic generated forms by model #
final user = Group(); //create object of the class
final key = GlobalKey<FormState>();
Form form = user.form(key);
/// youn can get easily form generated by model.
///and you can also get acess to data of the model by
Map data = user.formValue();
///Now you can easily pass data to add or update.
Get Form of existing data to update #
final user = Group(); //create object of the class
final key = GlobalKey<FormState>();
XDataModel? instance; /// this is the existing data.
Form form = user.form(key, instance);
/// youn can get easily form generated by model.
///and you can also get acess to data of the model by
Map data = user.formValue();
///Now you can easily pass data to add or update.
Admin Panel #
The package comes with pre-build admin panel. from it you can easily add, remove and modify Data.
import 'package:xmodels/admin/admin.dart';
Widget adminPanel = Admin(models: [Group()])
/// In models you have to pass the models class that you want to get in admin panel.
Features #
- Cross plateform
- Pre-Build Admin panel
- Easy to use
🚀 About Me #
I'm a software developer.