Complete refactoring SFM App Source Code

This commit is contained in:
anhtunz
2024-12-15 00:59:02 +07:00
parent caa73ca43c
commit 2e27d59278
247 changed files with 18390 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
import 'package:flutter/material.dart';
typedef BlocBuilder<T> = T Function();
typedef BlocDisposer<T> = Function(T);
abstract class BlocBase {
void dispose();
}
class _BlocProviderInherited<T> extends InheritedWidget {
const _BlocProviderInherited({
Key? key,
required Widget child,
required this.bloc,
}) : super(key: key, child: child);
final T bloc;
@override
bool updateShouldNotify(_BlocProviderInherited oldWidget) => false;
}
class BlocProvider<T extends BlocBase> extends StatefulWidget {
const BlocProvider({
Key? key,
required this.child,
required this.blocBuilder,
this.blocDispose,
}) : super(key: key);
final Widget child;
final BlocBuilder<T> blocBuilder;
final BlocDisposer<T>? blocDispose;
@override
BlocProviderState<T> createState() => BlocProviderState<T>();
static T of<T extends BlocBase>(BuildContext context) {
_BlocProviderInherited<T> provider = context
.getElementForInheritedWidgetOfExactType<_BlocProviderInherited<T>>()
?.widget as _BlocProviderInherited<T>;
return provider.bloc;
}
}
class BlocProviderState<T extends BlocBase> extends State<BlocProvider<T>> {
late T bloc;
@override
void initState() {
super.initState();
bloc = widget.blocBuilder();
}
@override
void dispose() {
if (widget.blocDispose != null) {
widget.blocDispose!(bloc);
} else {
bloc.dispose();
}
super.dispose();
}
@override
Widget build(BuildContext context) {
return _BlocProviderInherited<T>(
bloc: bloc,
child: widget.child,
);
}
}

View File

@@ -0,0 +1,142 @@
import 'dart:async';
import 'package:flutter/material.dart';
abstract class BasePageScreen extends StatefulWidget {
const BasePageScreen({Key? key}) : super(key: key);
}
abstract class BasePageScreenState<T extends BasePageScreen> extends State<T> {
bool _isBack = true;
bool _isHome = true;
bool _isShowTitle = true;
final _loadingController = StreamController<bool>();
String appBarTitle();
String appBarSubTitle();
void onClickBackButton();
void onClickHome();
void isBackButton(bool isBack) {
_isBack = isBack;
}
void isHomeButton(bool isHome) {
_isHome = isHome;
}
void isShowTitle(bool isShowTitle) {
_isShowTitle = isShowTitle;
}
void showLoading() {
_loadingController.add(true);
}
void hideLoading() {
_loadingController.add(false);
}
}
mixin BaseScreen<T extends BasePageScreen> on BasePageScreenState<T> {
Widget body();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
// flexibleSpace: Container(
// decoration: const BoxDecoration(
// image: DecorationImage(
// image: AssetImage('assets/images/bg_header.jpeg'),
// fit: BoxFit.cover)),
// ),
title: Column(
children: [
Visibility(
visible: _isShowTitle,
child: Text(
appBarTitle(),
style: const TextStyle(
color: Colors.white,
fontSize: 16,
),
),
),
Text(
appBarSubTitle(),
maxLines: _isShowTitle ? 1 : 2,
style: const TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold,
),
)
],
),
leading: _isBack
? IconButton(
icon: const Icon(
Icons.arrow_back_ios,
color: Colors.white,
),
onPressed: () {
// onClickBackButton();
Navigator.of(context).pushNamedAndRemoveUntil(
"/main", (Route<dynamic> route) => false);
},
)
: Container(),
actions: [
_isHome
? IconButton(
icon: const Icon(
Icons.home,
color: Colors.white,
),
onPressed: () {
onClickHome();
},
)
: Container()
],
),
body: Stack(
children: [
Container(
height: double.infinity,
color: Colors.white,
child: body(),
),
StreamBuilder(
stream: _loadingController.stream,
builder: (_, snapshot) {
return snapshot.data == true
? Positioned.fill(
child: _buildLoader(),
)
: const SizedBox();
},
),
],
));
}
Widget _buildLoader() {
return Container(
color: Colors.black54,
child: const Center(
child: CircularProgressIndicator(),
),
);
}
@override
void dispose() {
_loadingController.close();
super.dispose();
}
}

View File

@@ -0,0 +1,61 @@
import 'package:app_settings/app_settings.dart';
import 'package:flutter/material.dart';
import '../../../extention/context_extention.dart';
import '../../../services/language_services.dart';
class RequestPermissionDialog {
showRequestPermissionDialog(BuildContext context, IconData icon,
String dialogContent, AppSettingsType type) {
showDialog(
useRootNavigator: false,
context: context,
builder: (dialogContext) {
return AlertDialog(
title: Center(
child: Icon(icon),
),
content: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: context.paddingNormalVertical,
child: Text(
dialogContent,
textAlign: TextAlign.center,
style: const TextStyle(
fontWeight: FontWeight.bold, fontSize: 18),
),
),
Divider(height: context.lowValue),
GestureDetector(
onTap: () {
AppSettings.openAppSettings(type: type);
},
child: Padding(
padding:
context.paddingNormalVertical, // Cách giữa các phần tử
child: Text(appLocalization(context).allow_message,
style: const TextStyle(fontWeight: FontWeight.bold)),
),
),
Divider(height: context.lowValue),
GestureDetector(
onTap: () {
Navigator.of(dialogContext).pop(); // Đóng dialog
},
child: Padding(
padding:
context.paddingNormalVertical, // Cách giữa các phần tử
child: Text(appLocalization(context).decline_message,
style: const TextStyle(fontWeight: FontWeight.bold)),
),
),
],
),
);
},
);
}
}