mirror of
https://github.com/hmalik144/easy_cc_flutter.git
synced 2025-12-10 03:05:34 +00:00
Project lint checked and step added to config.yml
This commit is contained in:
56
lib/base_widget.dart
Normal file
56
lib/base_widget.dart
Normal file
@@ -0,0 +1,56 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:toast/toast.dart';
|
||||
|
||||
import 'base_viewmodel.dart';
|
||||
import 'Utils/constants.dart';
|
||||
import 'Utils/view_state.dart';
|
||||
import 'Utils/view_utils.dart';
|
||||
|
||||
abstract class BaseStatelessWidget<T extends BaseViewmodel>
|
||||
extends StatelessWidget {
|
||||
const BaseStatelessWidget({super.key});
|
||||
|
||||
T createViewModel();
|
||||
|
||||
Widget displayWidget(BuildContext context, T model, Widget? child);
|
||||
|
||||
@override
|
||||
// ignore: avoid_renaming_method_parameters
|
||||
Widget build(BuildContext parent) {
|
||||
ToastContext().init(parent);
|
||||
return Scaffold(
|
||||
body: Container(
|
||||
padding: const EdgeInsets.all(paddingGlobal),
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [colourTwo, colourThree])),
|
||||
child: ViewModelBuilder<T>.reactive(
|
||||
viewModelBuilder: () => createViewModel(),
|
||||
builder: (context, model, child) {
|
||||
var state = model.viewState;
|
||||
|
||||
if (state is HasStarted) {
|
||||
onStarted();
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
} else if (state is HasError) {
|
||||
WidgetsBinding.instance.addPostFrameCallback(
|
||||
(_) => ViewUtils.displayToast(parent, state.error));
|
||||
}
|
||||
return Center(
|
||||
child: displayWidget(context, model, child),
|
||||
);
|
||||
},
|
||||
onModelReady: (T model) => onModelReady(model)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void onModelReady(T model) {}
|
||||
|
||||
void onStarted() {}
|
||||
}
|
||||
Reference in New Issue
Block a user