base_state.dart 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import 'package:flutter/material.dart';
  2. import 'package:lszlgl/config/pics.dart';
  3. export 'package:lszlgl/config/pics.dart';
  4. export 'package:lszlgl/router/my_navigator.dart';
  5. export 'package:lszlgl/router/my_router.dart';
  6. abstract class BaseState<T extends StatefulWidget> extends State<T> {
  7. /// 隐藏软键盘
  8. void hideKeyboard() {
  9. FocusScopeNode currentFocus = FocusScope.of(context);
  10. if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
  11. FocusManager.instance.primaryFocus?.unfocus();
  12. }
  13. }
  14. AppBar myAppBar({
  15. String title = '',
  16. String? titleIcon,
  17. bool autoLeading = true,
  18. PreferredSizeWidget? bottom,
  19. }) {
  20. return AppBar(
  21. title: Text(title),
  22. bottom: bottom,
  23. automaticallyImplyLeading: autoLeading,
  24. );
  25. }
  26. /// 带背景图的Scaffold
  27. Widget myScaffold({required Widget child}) {
  28. return Scaffold(
  29. body: Stack(
  30. children: [
  31. SizedBox(width: double.infinity, child: Image.asset(imgHomeTopBg)),
  32. child,
  33. ],
  34. ),
  35. );
  36. }
  37. }