base_state.dart 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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: Text(title),
  31. bottom: bottom,
  32. automaticallyImplyLeading: autoLeading,
  33. toolbarHeight: toolbarHeight,
  34. actions: actions,
  35. systemOverlayStyle: SystemUiOverlayStyle.light.copyWith(
  36. systemNavigationBarColor: naviBarColor ?? MyColor.c_background,
  37. systemNavigationBarIconBrightness: naviBarBrightness ?? Brightness.dark,
  38. ),
  39. );
  40. }
  41. /// 带背景图的Scaffold
  42. Widget myScaffold({required Widget child}) {
  43. return Scaffold(
  44. body: Stack(
  45. children: [
  46. SizedBox(width: double.infinity, child: Image.asset(imgHomeTopBg)),
  47. child,
  48. ],
  49. ),
  50. );
  51. }
  52. }