This lib gives (AmDataProvider<T>) as data provider and (AmRefreshWidget<T>) as wrapper to the widgets that must be changed when provider data changed.
https://marketplace.visualstudio.com/items?itemName=Amr-MAM.am-state
import 'package:am_state/am_state.dart';
-
we need to create a normal class which has all properity we need to display in the UI page
-
we need to create a class for the controller extended from [AmController<State_Class>]
-
class HomeState { int number = 0; String title = 'hello'; }
-
Easily if you installed the extension you can write
amcont
then choose the snippet code and fill the fieldsclass HomeController extends AmController<HomeState> { HomeController(super.state); void increaseby1() { state.number++; refresh(); } void decreaseby1() { state.number--; refresh(); } void changeTitle() { state.title = '${state.title} Hi;\n'; refresh(); } // use the command 'refresh();' inside functions to update the view widget // --------------------------------------------------------------------------- @override void onDispose() {} @override void onInit() {} }
-
Easily if you installed the extension you can write
amview
then choose the snippet code and fill the fieldsclass MyHomePage extends AmViewWidget<HomeController> { const MyHomePage({super.key}); @override Widget build(BuildContext context, am) { return Scaffold( appBar: AppBar( title: const Text('Hi Am State App Test'), ), body: ListView( padding: const EdgeInsets.all(8), children: [ Text( 'Wow ${am.state.title}', style: const TextStyle( fontSize: 18, fontWeight: FontWeight.bold, color: Colors.blue, ), ), Text( 'num ---- ${am.state.number}', style: const TextStyle( fontSize: 22, fontWeight: FontWeight.bold, color: Colors.red, ), ), ], ), floatingActionButton: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ ElevatedButton( onPressed: () => am.increaseby1(), child: const Icon(Icons.plus_one), ), ElevatedButton( onPressed: () => am.decreaseby1(), child: const Icon(Icons.remove), ), ElevatedButton( onPressed: () => am.changeTitle(), child: const Icon(Icons.change_circle), ), ], ), ); } @override get config => HomeController(HomeModel()); }
AmChannel<String>.of('/home/adminName').amSend = 'Amr Mostafa';
print(AmChannel<String>.of('/home/adminName').amGet);
print(AmChannel<String>.of('/home/adminName').amGetPrevious);
AmChannel.of('/home/adminName').delete();
final dataProvider = AmDataProvider<int>(
initialData: 0,
providerId: 'providerId',
);
dataProvider.initialize; // you need to use this if you want to access the provider with its id instead of its name at first time.
// OR
final dataProvider = AmDataProvider<int>();
// You can't access this with id and dying if disposed.
// You can only access this with its name ex:[dataProvider] if still alive.
// if you added a providerId the provider won't die.
int? num = AmDataProvider<int>.of('providerId').data;
class Example extends StatelessWidget {
const Example({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
child: AmRefreshWidget<int>(
amDataProvider: AmDataProvider<int>.of('providerId'),
builder: (ctx, value) {
return Text('$value');
},
),
);
}
}
dataProvider.silentDataSet = dataProvider.data! + 1;
// OR
AmDataProvider<String>.of('providerId').silentDataSet = 'any data';
dataProvider.data = dataProvider.data! + 1;
// OR
AmDataProvider<String>.of('providerId').data = 'Some Data';
dataProvider.activeFunction = () {
//...Some Code....instantinously invoked then states refreshed
};
// OR
AmDataProvider<String>.of('providerId').activeFunction = () {
//...Some Code....instantinously invoked then states refreshed
};
if(dataProvider.data == dataProvider.previousData){
//...Some Code...
}else{
//...Some Code...
}
/// To save an object
object.amSave(id);
'Amr Mostafa'.amSave('userName123'); // Example
/// To get the saved object if null the defaultObject is Returned
/// Note: the saved object and the default object must be in the same type
var data = defaultObject.amGet(id);
var userName = 'Not found'.amGet('userName123'); //Example
/// OR you can get saved data in that way
/// Null is Returned if none is saved.
var data = AmMemory.amGetIfSaved<DataType>(id);
var userName = AmMemory.amGetIfSaved<String>('userName123') ?? 'Not found'; // Example
final listener = AmFunctionTrigger<int>(
amDataProvider: AmDataProvider<int>.of('providerId'),
function: (value){ ... some code ... }
);
listener.start; // You need to use this line anywhere
listener.cancel();
listener.activate();
child: AmRefreshWidget<int>(
amDataProvider: dataProvider,
builder: (ctx, value) {
/// This controller you may send as a parameter anyway but you have rarely to do this_
/// Because the [AmDataProvider] may do the same goal.
var controller = AmRefreshWidgetController.of(ctx);
/// When this code block is called this variable will have the last value.
/// if it is the frist time to call this code, this variable will have 5 as initial value.
var intState = controller.statePoint<int>(id: 1, initialValue: 5);
///Dummy Code to use the statePoint variable.
intState.value = value! * (intState.value);
return Text('${intState.value}');
},
),
-
import 'package:am_state/am_state.dart'; var uid = AmTools.genUniqueId();
-
import 'package:am_state/am_state.dart'; var uid = AmTools.genUniqueIdMicro();
-
import 'package:am_state/am_state.dart'; var hash = AmTools.calculateMD5Hash(" ------- string ------");
-
import 'package:am_state/am_state.dart'; var hash = AmTools.calculateMD5HashFromFile(file);
-
import 'package:am_state/am_state.dart'; var hash = AmTools.calculateMD5HashFromBytes(byteList);
-
import 'package:am_state/am_state.dart'; bool x = "true ".toBool(); String x = date.amDateFormatYYMMDD(); String x = date.amTimeFormatHHMMSS(); String x = date.amTimeFormatHHMMPMam(); String x = duration.convertToString(); String x = duration.convertToWatchString(); String x = file.getFileName; String x = file.getFileExtension; /// ex. split [1, 2, 3, 3, 4, 5, 3, 3, 6, 7] for [3, 3] /// result => [[1, 2], [4, 5], [6, 7]] List<List<T>> x = list.splitList(delimiterList);