basic_page.dart 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_riverpod/flutter_riverpod.dart';
  3. import 'package:tp5/widgets/nav_drawer.dart';
  4. class BasicPage extends ConsumerStatefulWidget {
  5. final String? title;
  6. final Widget body;
  7. final AppBar? appBar;
  8. final Widget? drawer;
  9. final Widget? floatingActionButton;
  10. final Widget? bottomSheet;
  11. final List<Widget>? persistentFooterButtons;
  12. final dynamic floatingActionButtonLocation;
  13. final Widget? bottomNavigationBar;
  14. final List<Widget>? actions;
  15. const BasicPage({
  16. this.title,
  17. required this.body,
  18. this.drawer,
  19. this.appBar,
  20. this.floatingActionButton,
  21. this.bottomSheet,
  22. this.persistentFooterButtons,
  23. this.floatingActionButtonLocation,
  24. this.bottomNavigationBar,
  25. this.actions,
  26. super.key,
  27. });
  28. @override
  29. ConsumerState<ConsumerStatefulWidget> createState() => _BasicPageState();
  30. }
  31. class _BasicPageState extends ConsumerState<BasicPage> {
  32. @override
  33. Widget build(BuildContext context) {
  34. return Scaffold(
  35. bottomNavigationBar: widget.bottomNavigationBar,
  36. appBar: widget.appBar ??
  37. AppBar(
  38. title: Row(
  39. children: [
  40. Text(widget.title ?? "myLog"),
  41. // Switch(
  42. // activeColor: Colors.orange,
  43. // onChanged: (value) {
  44. // ref.read(appThemeProvider.notifier).state = value;
  45. // },
  46. // value: isDarkMode)
  47. ],
  48. ),
  49. actions: [
  50. ...widget.actions ?? [],
  51. if (ref.watch(isLoadingProvider))
  52. const Padding(
  53. padding: EdgeInsets.all(10),
  54. child: CircularProgressIndicator())
  55. ],
  56. ),
  57. body: widget.body,
  58. drawer: widget.drawer ?? const NavDrawer(),
  59. floatingActionButton: widget.floatingActionButton,
  60. floatingActionButtonLocation: widget.floatingActionButtonLocation,
  61. bottomSheet: widget.bottomSheet,
  62. persistentFooterButtons: widget.persistentFooterButtons,
  63. );
  64. }
  65. }
  66. final isLoadingProvider = StateProvider<bool>(
  67. // We return the default sort type, here name.
  68. (ref) => false,
  69. );