base_state.dart 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/services.dart';
  3. import 'package:lszlgl/config/colors.dart';
  4. import 'package:lszlgl/config/pics.dart';
  5. export 'package:lszlgl/config/pics.dart';
  6. export 'package:lszlgl/router/my_navigator.dart';
  7. export 'package:lszlgl/router/my_router.dart';
  8. export 'package:lszlgl/ext/value_notifier_ext.dart';
  9. abstract class BaseState<T extends StatefulWidget> extends State<T> {
  10. EdgeInsets get mediaPadding => MediaQuery.of(context).padding;
  11. double getBottomPadding(double defaultValue) => mediaPadding.bottom != 0 ? mediaPadding.bottom : defaultValue;
  12. /// 隐藏软键盘
  13. void hideKeyboard() {
  14. FocusScopeNode currentFocus = FocusScope.of(context);
  15. if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
  16. FocusManager.instance.primaryFocus?.unfocus();
  17. }
  18. }
  19. AppBar myAppBar({
  20. String title = '',
  21. String? titleIcon,
  22. bool autoLeading = true,
  23. PreferredSizeWidget? bottom,
  24. double? toolbarHeight,
  25. List<Widget>? actions,
  26. Color? naviBarColor,
  27. Brightness? naviBarBrightness,
  28. }) {
  29. return AppBar(
  30. title: FittedBox(
  31. fit: BoxFit.scaleDown,
  32. child: Text(title)),
  33. bottom: bottom,
  34. automaticallyImplyLeading: autoLeading,
  35. toolbarHeight: toolbarHeight,
  36. actions: actions,
  37. systemOverlayStyle: SystemUiOverlayStyle.light.copyWith(
  38. systemNavigationBarColor: naviBarColor ?? MyColor.c_background,
  39. systemNavigationBarIconBrightness: naviBarBrightness ?? Brightness.dark,
  40. ),
  41. );
  42. }
  43. /// 带背景图的Scaffold
  44. Widget myScaffold({required Widget child}) {
  45. return Scaffold(
  46. body: Stack(
  47. children: [
  48. SizedBox(width: double.infinity, child: Image.asset(imgHomeTopBg)),
  49. child,
  50. ],
  51. ),
  52. );
  53. }
  54. }