Showing
1 changed file
with
47 additions
and
37 deletions
@@ -3,39 +3,11 @@ import 'package:flutter/widgets.dart'; | @@ -3,39 +3,11 @@ import 'package:flutter/widgets.dart'; | ||
3 | import '../../../get.dart'; | 3 | import '../../../get.dart'; |
4 | import 'get_view.dart'; | 4 | import 'get_view.dart'; |
5 | 5 | ||
6 | -abstract class _GetResponsive<T> extends GetView<T> { | ||
7 | - final ResponsiveScreen screen; | ||
8 | - _GetResponsive(ResponsiveScreenSettings settings, {Key? key}) | ||
9 | - : screen = ResponsiveScreen(settings), | ||
10 | - super(key: key); | ||
11 | - | ||
12 | - Widget? builder(); | ||
13 | - Widget? phone(); | ||
14 | - Widget? tablet(); | ||
15 | - Widget? desktop(); | ||
16 | - Widget? watch(); | ||
17 | -} | 6 | +mixin GetResponsiveMixin on Widget { |
7 | + ResponsiveScreen get screen; | ||
8 | + bool get alwaysUseBuilder; | ||
18 | 9 | ||
19 | -/// Extend this widget to build responsive view. | ||
20 | -/// this widget contains the `screen` property that have all | ||
21 | -/// information about the screen size and type. | ||
22 | -/// You have two options to build it. | ||
23 | -/// 1- with `builder` method you return the widget to build. | ||
24 | -/// 2- with methods `desktop`, `tablet`,`phone`, `watch`. the specific | ||
25 | -/// method will be built when the screen type matches the method | ||
26 | -/// when the screen is [ScreenType.Tablet] the `tablet` method | ||
27 | -/// will be exuded and so on. | ||
28 | -/// Note if you use this method please set the | ||
29 | -/// property `alwaysUseBuilder` to false | ||
30 | -/// With `settings` property you can set the width limit for the screen types. | ||
31 | -class GetResponsiveView<T> extends _GetResponsive<T> { | ||
32 | - final bool alwaysUseBuilder = true; | ||
33 | - GetResponsiveView( | ||
34 | - {alwaysUseBuilder, | ||
35 | - ResponsiveScreenSettings settings = const ResponsiveScreenSettings(), | ||
36 | - Key? key}) | ||
37 | - : super(settings, key: key); | ||
38 | - @override | 10 | + @protected |
39 | Widget build(BuildContext context) { | 11 | Widget build(BuildContext context) { |
40 | screen.context = context; | 12 | screen.context = context; |
41 | Widget? widget; | 13 | Widget? widget; |
@@ -58,22 +30,60 @@ class GetResponsiveView<T> extends _GetResponsive<T> { | @@ -58,22 +30,60 @@ class GetResponsiveView<T> extends _GetResponsive<T> { | ||
58 | return watch() ?? phone() ?? tablet() ?? desktop() ?? builder()!; | 30 | return watch() ?? phone() ?? tablet() ?? desktop() ?? builder()!; |
59 | } | 31 | } |
60 | 32 | ||
61 | - @override | ||
62 | Widget? builder() => null; | 33 | Widget? builder() => null; |
63 | 34 | ||
64 | - @override | ||
65 | Widget? desktop() => null; | 35 | Widget? desktop() => null; |
66 | 36 | ||
67 | - @override | ||
68 | Widget? phone() => null; | 37 | Widget? phone() => null; |
69 | 38 | ||
70 | - @override | ||
71 | Widget? tablet() => null; | 39 | Widget? tablet() => null; |
72 | 40 | ||
73 | - @override | ||
74 | Widget? watch() => null; | 41 | Widget? watch() => null; |
75 | } | 42 | } |
76 | 43 | ||
44 | +/// Extend this widget to build responsive view. | ||
45 | +/// this widget contains the `screen` property that have all | ||
46 | +/// information about the screen size and type. | ||
47 | +/// You have two options to build it. | ||
48 | +/// 1- with `builder` method you return the widget to build. | ||
49 | +/// 2- with methods `desktop`, `tablet`,`phone`, `watch`. the specific | ||
50 | +/// method will be built when the screen type matches the method | ||
51 | +/// when the screen is [ScreenType.Tablet] the `tablet` method | ||
52 | +/// will be exuded and so on. | ||
53 | +/// Note if you use this method please set the | ||
54 | +/// property `alwaysUseBuilder` to false | ||
55 | +/// With `settings` property you can set the width limit for the screen types. | ||
56 | +class GetResponsiveView<T> extends GetView<T> with GetResponsiveMixin { | ||
57 | + @override | ||
58 | + final bool alwaysUseBuilder; | ||
59 | + | ||
60 | + @override | ||
61 | + final ResponsiveScreen screen; | ||
62 | + | ||
63 | + GetResponsiveView({ | ||
64 | + this.alwaysUseBuilder = false, | ||
65 | + ResponsiveScreenSettings settings = const ResponsiveScreenSettings(), | ||
66 | + Key? key, | ||
67 | + }) : screen = ResponsiveScreen(settings), | ||
68 | + super(key: key); | ||
69 | +} | ||
70 | + | ||
71 | +class GetResponsiveWidget<T extends GetLifeCycleBase?> extends GetWidget<T> | ||
72 | + with GetResponsiveMixin { | ||
73 | + @override | ||
74 | + final bool alwaysUseBuilder; | ||
75 | + | ||
76 | + @override | ||
77 | + final ResponsiveScreen screen; | ||
78 | + | ||
79 | + GetResponsiveWidget({ | ||
80 | + this.alwaysUseBuilder = false, | ||
81 | + ResponsiveScreenSettings settings = const ResponsiveScreenSettings(), | ||
82 | + Key? key, | ||
83 | + }) : screen = ResponsiveScreen(settings), | ||
84 | + super(key: key); | ||
85 | +} | ||
86 | + | ||
77 | class ResponsiveScreenSettings { | 87 | class ResponsiveScreenSettings { |
78 | /// When the width is greater als this value | 88 | /// When the width is greater als this value |
79 | /// the display will be set as [ScreenType.Desktop] | 89 | /// the display will be set as [ScreenType.Desktop] |
-
Please register or login to post a comment