Skip to content

Commit

Permalink
add folder: button, dialog, config
Browse files Browse the repository at this point in the history
  • Loading branch information
duong2417 committed Nov 10, 2024
1 parent 2668c42 commit 0db2da9
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 1 deletion.
20 changes: 20 additions & 0 deletions lib/_shared/button/my_close_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:flutter/material.dart';

class MyCloseButton extends StatelessWidget {
const MyCloseButton({super.key, required this.onPressed});
final void Function() onPressed;
@override
Widget build(BuildContext context) {
return IconButton(
icon: Container(
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: Colors.grey,
),
child: const Icon(Icons.close, size: 20)), //24
padding: EdgeInsets.zero, // Không có padding
constraints: const BoxConstraints(), // Loại bỏ các ràng buộc mặc định
onPressed: onPressed,
);
}
}
35 changes: 35 additions & 0 deletions lib/_shared/button/my_elevated_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:flutter/material.dart';

// ignore: must_be_immutable
class MyElevatedButton extends StatelessWidget {
const MyElevatedButton(
{super.key,
required this.onPressed,
required this.buttonName,
this.textColor,
this.backgroundColor,
this.width,
this.height});
final String buttonName;
final Function()? onPressed;
final Color? textColor;
final Color? backgroundColor;
final double? width;
final double? height;
@override
Widget build(BuildContext context) {
return ElevatedButton(
style: ButtonStyle(
// fixedSize:MaterialStatePropertyAll(Size(width??,height)),
// textStyle: MaterialStatePropertyAll(
// GoogleFonts.sarabun(
// color: textColor, fontWeight: FontWeight.bold, fontSize: 12)
// ),
elevation: WidgetStateProperty.all(6),
backgroundColor:
WidgetStatePropertyAll(backgroundColor ?? Colors.transparent),
),
onPressed: onPressed,
child: Text(buttonName));
}
}
28 changes: 28 additions & 0 deletions lib/_shared/dialog/loading_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:flutter/cupertino.dart';
import '../../config/routes/navigator.dart';
import '../../main.dart';

class LoadingDialog {
static showLoading({BuildContext? context}) {
showCupertinoDialog(
context: globalAppContext ?? context!,
builder: (context) {
return const CupertinoAlertDialog(
content: LoadingState(),
);
});
}

static hideLoading() {
pop();
}
}

class LoadingState extends StatelessWidget {
const LoadingState({super.key});

@override
Widget build(BuildContext context) {
return const CupertinoActivityIndicator();
}
}
66 changes: 66 additions & 0 deletions lib/_shared/dialog/popup/message_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../config/routes/navigator.dart';
import '../../../main.dart';

class MessageDialog {
static void showMessageDialog({
Widget? contentWidget,
String? contentText,
String? closeText = 'Close',
List<Widget>? actions,
bool tapOutsideToClose = false,
Color? color,
Widget? titleWidget,
String? titleText,
Function()? onTapClose,
}) {
showCupertinoModalPopup<void>(
context: globalAppContext!,
barrierDismissible: tapOutsideToClose,
builder: (BuildContext context) {
return CupertinoAlertDialog(
title: titleWidget ??
Text(
titleText ?? '',
style: const TextStyle(
color: Colors.blue, fontWeight: FontWeight.bold),
),
content: Material(
color: Colors.transparent,
child: contentWidget ??
Text(contentText ?? '',
textAlign: TextAlign.start,
style: const TextStyle(fontSize: 16)),
),
actions: actions ??
[
TextButton(
onPressed: onTapClose ??
() {
pop();
},
child: Text(closeText ?? 'OK'))
],
);
},
);
}

static void showError({
BuildContext? context,
String? contentText,
Widget? contentWidget,
String? closeText = 'Close',
List<Widget>? actions,
bool tapOutsideToClose = false,
}) {
showMessageDialog(
color: Colors.red,
contentText: contentText,
contentWidget: contentWidget,
closeText: closeText,
actions: actions,
tapOutsideToClose: tapOutsideToClose);
}
}
99 changes: 99 additions & 0 deletions lib/_shared/widgets/my_textfield.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import 'package:flutter/material.dart';

class TextFieldInput extends StatelessWidget {
const TextFieldInput({
super.key,
this.keyboardType,
this.labelText,
this.style,
this.obscureText = false,
this.autocorrect,
this.onChanged,
this.suffixIcon,
this.suffix,
this.suffixText,
this.suffixStyle,
this.suffixIconColor,
this.suffixIconConstraints,
this.filled,
this.fillColor,
this.readOnly = false,
this.prefixIcon,
this.controller,
this.hintText,
this.hintStyle,
this.errorText,
this.onFieldSubmitted,
this.focusNode,
// this.initText,
this.minLines,
this.maxLines,
this.autofocus = false,
});
final TextInputType? keyboardType;
final String? labelText, hintText;
final bool obscureText;
final bool? autocorrect;
final ValueChanged<String>? onChanged;
final Widget? suffixIcon;
final Widget? prefixIcon;
final Widget? suffix;
final String? suffixText;
final TextStyle? suffixStyle;
final Color? suffixIconColor;
final BoxConstraints? suffixIconConstraints;
final bool? filled;
final Color? fillColor;
final bool readOnly;
final TextEditingController? controller;
final TextStyle? hintStyle;
final String? errorText;
final void Function(String)? onFieldSubmitted;
final FocusNode? focusNode;
final int? minLines;
final int? maxLines;
final TextStyle? style;
final bool autofocus;
@override
Widget build(BuildContext context) {
return TextFormField(
autofocus: autofocus,
onChanged: onChanged,
style: style ?? (readOnly ? const TextStyle(color: Colors.grey) : null),
maxLines: maxLines,
minLines: minLines,
focusNode: focusNode,
onFieldSubmitted: onFieldSubmitted,
obscureText: obscureText,
controller: controller,
keyboardType: keyboardType,
readOnly: readOnly,
cursorColor: Colors.black,
decoration: InputDecoration(
errorText: errorText,
hintText: hintText,
counterStyle: const TextStyle(color: Colors.pink),
labelStyle: const TextStyle(color: Colors.black),
hintStyle: hintStyle ?? const TextStyle(color: Colors.grey),
prefixIcon: prefixIcon,
suffixIcon: suffixIcon,
suffix: suffix,
contentPadding:
const EdgeInsets.symmetric(vertical: 10, horizontal: 15),
labelText: labelText,
enabledBorder: const OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey)),
focusColor: Colors.black,
focusedBorder: const OutlineInputBorder(
borderSide: BorderSide(color: Colors.black)),
border: const OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey)),
filled: filled ?? true,
fillColor: readOnly
? (fillColor ?? Colors.grey)
: fillColor ??
Colors.white,
),
);
}
}
16 changes: 16 additions & 0 deletions lib/config/routes/navigator.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:flutter/material.dart';

import '../../main.dart';

push(Widget page) {
return navigatorKey.currentState
?.push(MaterialPageRoute(builder: (context) => page));
}
pushReplacement(Widget page) {
return navigatorKey.currentState
?.pushReplacement(MaterialPageRoute(builder: (context) => page));
}

pop({dynamic arguments}) {
navigatorKey.currentState?.pop(arguments ?? {});
}
Empty file.
63 changes: 63 additions & 0 deletions lib/config/themes/my_text_style.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'package:flutter/material.dart';

class MyTextStyle {
static Text errorText(String text) {
return Text(text,
style: const TextStyle(
color: Colors.red, fontSize: 18, fontWeight: FontWeight.bold));
}

Text noElement(String text) {
return Text(
text,
style: const TextStyle(
color: Colors.grey, fontSize: 18, fontWeight: FontWeight.bold),
);
}

static const translate =
TextStyle(fontSize: 16, color: Colors.amber, fontStyle: FontStyle.italic);
static const greySemiBold = TextStyle(
color: Color.fromRGBO(179, 179, 179, 100),
fontWeight: FontWeight.w600,
fontSize: 14, //11,
);

static const titleAppbar = TextStyle(
fontWeight: FontWeight.w600,
fontSize: 18,
);

// static const inboxTextBlack = TextStyle(
// color: Colors.black,
// fontWeight: FontWeight.w500, //medium
// fontSize: 12,
// );
// static const inboxTextWhite = TextStyle(
// color: Colors.white.withOpacity(1),
// fontWeight: FontWeight.w400, //medium
// fontSize: 16,
// );
static const heading1 = TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
);

static const heading2 = TextStyle(
fontWeight: FontWeight.w400,
fontSize: 14,
);
static const textSelected = TextStyle(
fontWeight: FontWeight.w400,
fontSize: 14,
height: 1.2,
backgroundColor: Colors.brown, //AppColor.backgroundText,
decoration: TextDecoration.none,
);
static const normal = TextStyle(
fontWeight: FontWeight.w400,
fontSize: 14,
height: 1.2,
decoration: TextDecoration.none,
);
}
3 changes: 2 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import 'package:public_chat/firebase_options.dart';
import 'package:public_chat/service_locator/service_locator.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

BuildContext? get globalAppContext => navigatorKey.currentContext;
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
void main() async {
WidgetsFlutterBinding.ensureInitialized();

Expand Down

0 comments on commit 0db2da9

Please sign in to comment.