refactor: MediaQuery as InheritedModel

This commit is contained in:
DenserMeerkat
2024-05-23 23:37:56 +05:30
parent 5ef37914b3
commit 5a8150953e
15 changed files with 97 additions and 100 deletions

View File

@ -106,7 +106,7 @@ class DashApp extends ConsumerWidget {
final isDarkMode =
ref.watch(settingsProvider.select((value) => value.isDark));
final isLargeMobile =
MediaQuery.of(context).size.width > kMinWindowSize.width;
MediaQuery.sizeOf(context).width > kMinWindowSize.width;
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(

View File

@ -143,7 +143,7 @@ class _RequestListState extends ConsumerState<RequestList> {
.select((value) => value.alwaysShowCollectionPaneScrollbar));
final filterQuery = ref.watch(searchQueryProvider).trim();
final isMobile =
kIsMobile && MediaQuery.of(context).size.width < kMinWindowSize.width;
kIsMobile && MediaQuery.sizeOf(context).width < kMinWindowSize.width;
return Scrollbar(
controller: controller,
@ -153,7 +153,7 @@ class _RequestListState extends ConsumerState<RequestList> {
? ReorderableListView.builder(
padding: isMobile
? EdgeInsets.only(
bottom: MediaQuery.of(context).padding.bottom,
bottom: MediaQuery.paddingOf(context).bottom,
right: 8,
)
: kPe8,
@ -201,7 +201,7 @@ class _RequestListState extends ConsumerState<RequestList> {
: ListView(
padding: kIsMobile
? EdgeInsets.only(
bottom: MediaQuery.of(context).padding.bottom,
bottom: MediaQuery.paddingOf(context).bottom,
right: 8,
)
: kPe8,

View File

@ -12,7 +12,7 @@ class RequestEditor extends StatelessWidget {
@override
Widget build(BuildContext context) {
final isMobile =
kIsMobile && MediaQuery.of(context).size.width < kMinWindowSize.width;
kIsMobile && MediaQuery.sizeOf(context).width < kMinWindowSize.width;
return isMobile
? const Padding(
padding: kPb10,

View File

@ -10,7 +10,7 @@ class EditorPaneRequestURLCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
final isMobile =
kIsMobile && MediaQuery.of(context).size.width < kMinWindowSize.width;
kIsMobile && MediaQuery.sizeOf(context).width < kMinWindowSize.width;
return Card(
elevation: 0,
shape: RoundedRectangleBorder(

View File

@ -44,92 +44,88 @@ class _MobileDashboardState extends ConsumerState<MobileDashboard> {
) {
final GlobalKey<InnerDrawerState> innerDrawerKey =
ref.watch(mobileDrawerKeyProvider);
final isLargeMobile = MediaQuery.sizeOf(context).width > kLargeMobileWidth;
return AnnotatedRegion<SystemUiOverlayStyle>(
value: FlexColorScheme.themedSystemNavigationBar(
context,
opacity: 0,
noAppBar: true,
),
child: LayoutBuilder(
builder: (context, constraints) {
final isLargeMobile = constraints.maxWidth > kLargeMobileWidth;
return Stack(
alignment: AlignmentDirectional.bottomCenter,
children: [
InnerDrawer(
key: innerDrawerKey,
swipe: true,
swipeChild: true,
onTapClose: true,
offset: isLargeMobile
? const IDOffset.only(left: 0.1, right: 1)
: const IDOffset.only(left: 0.7, right: 1),
boxShadow: [
BoxShadow(
offset: const Offset(1, 0),
color: Theme.of(context).colorScheme.onInverseSurface,
blurRadius: 0,
),
],
colorTransitionChild: Colors.transparent,
colorTransitionScaffold: Colors.transparent,
rightAnimationType: InnerDrawerAnimation.linear,
backgroundDecoration:
BoxDecoration(color: Theme.of(context).colorScheme.surface),
onDragUpdate: (value, direction) {
drawerDirection.value = direction;
if (value > 0.98 && direction == InnerDrawerDirection.start) {
dragPosition.value = 1;
} else {
dragPosition.value = 0;
}
},
innerDrawerCallback: (isOpened) {
if (drawerDirection.value == InnerDrawerDirection.start) {
setState(() {
isLeftDrawerOpen = isOpened;
});
}
},
leftChild: const LeftDrawer(
drawerContent: CollectionPane(),
),
rightChild: const ResponseDrawer(),
scaffold: ValueListenableBuilder<double>(
valueListenable: dragPosition,
builder: (context, value, child) {
return Container(
color: calculateBackgroundColor(value),
child: child,
);
},
child: ClipRRect(
borderRadius:
const BorderRadius.only(topLeft: Radius.circular(8)),
child: SafeArea(
bottom: false,
child: RequestsPage(
innerDrawerKey: innerDrawerKey,
),
),
child: Stack(
alignment: AlignmentDirectional.bottomCenter,
children: [
InnerDrawer(
key: innerDrawerKey,
swipe: true,
swipeChild: true,
onTapClose: true,
offset: isLargeMobile
? const IDOffset.only(left: 0.1, right: 1)
: const IDOffset.only(left: 0.7, right: 1),
boxShadow: [
BoxShadow(
offset: const Offset(1, 0),
color: Theme.of(context).colorScheme.onInverseSurface,
blurRadius: 0,
),
],
colorTransitionChild: Colors.transparent,
colorTransitionScaffold: Colors.transparent,
rightAnimationType: InnerDrawerAnimation.linear,
backgroundDecoration:
BoxDecoration(color: Theme.of(context).colorScheme.surface),
onDragUpdate: (value, direction) {
drawerDirection.value = direction;
if (value > 0.98 && direction == InnerDrawerDirection.start) {
dragPosition.value = 1;
} else {
dragPosition.value = 0;
}
},
innerDrawerCallback: (isOpened) {
if (drawerDirection.value == InnerDrawerDirection.start) {
setState(() {
isLeftDrawerOpen = isOpened;
});
}
},
leftChild: const LeftDrawer(
drawerContent: CollectionPane(),
),
rightChild: const ResponseDrawer(),
scaffold: ValueListenableBuilder<double>(
valueListenable: dragPosition,
builder: (context, value, child) {
return Container(
color: calculateBackgroundColor(value),
child: child,
);
},
child: ClipRRect(
borderRadius:
const BorderRadius.only(topLeft: Radius.circular(8)),
child: SafeArea(
bottom: false,
child: RequestsPage(
innerDrawerKey: innerDrawerKey,
),
),
),
if (!isLargeMobile)
AnimatedPositioned(
bottom: isLeftDrawerOpen
? 0
: -(72 + MediaQuery.of(context).padding.bottom),
left: 0,
right: 0,
height: 70 + MediaQuery.of(context).padding.bottom,
duration: const Duration(milliseconds: 200),
curve: Curves.easeOut,
child: const BottomNavBar(),
),
],
);
},
),
),
if (!isLargeMobile)
AnimatedPositioned(
bottom: isLeftDrawerOpen
? 0
: -(72 + MediaQuery.paddingOf(context).bottom),
left: 0,
right: 0,
height: 70 + MediaQuery.paddingOf(context).bottom,
duration: const Duration(milliseconds: 200),
curve: Curves.easeOut,
child: const BottomNavBar(),
),
],
),
);
}

View File

@ -8,9 +8,9 @@ class LeftDrawer extends StatelessWidget {
@override
Widget build(BuildContext context) {
final isLargeMobile = MediaQuery.of(context).size.width > kLargeMobileWidth;
final isLargeMobile = MediaQuery.sizeOf(context).width > kLargeMobileWidth;
return Container(
padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
padding: EdgeInsets.only(top: MediaQuery.paddingOf(context).top),
color: Theme.of(context).colorScheme.onInverseSurface,
child: Drawer(
backgroundColor: Colors.transparent,
@ -19,9 +19,10 @@ class LeftDrawer extends StatelessWidget {
padding: const EdgeInsets.only(right: 16),
child: Container(
padding: EdgeInsets.only(
left: MediaQuery.paddingOf(context).left,
bottom: isLargeMobile
? MediaQuery.of(context).padding.bottom
: 70 + MediaQuery.of(context).padding.bottom),
? MediaQuery.paddingOf(context).bottom
: 70 + MediaQuery.paddingOf(context).bottom),
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,

View File

@ -15,10 +15,10 @@ class BottomNavBar extends ConsumerWidget {
children: [
Container(
alignment: Alignment.topCenter,
height: 70 + MediaQuery.of(context).padding.bottom,
width: MediaQuery.of(context).size.width,
height: 70 + MediaQuery.paddingOf(context).bottom,
width: MediaQuery.sizeOf(context).width,
padding:
EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom),
EdgeInsets.only(bottom: MediaQuery.paddingOf(context).bottom),
decoration: BoxDecoration(
border: Border(
top: BorderSide(

View File

@ -17,7 +17,7 @@ class PageBase extends StatelessWidget {
),
body: Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).padding.bottom,
bottom: MediaQuery.paddingOf(context).bottom,
),
child: scaffoldBody,
),

View File

@ -130,10 +130,10 @@ class RequestPageBottombar extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
height: 60 + MediaQuery.of(context).padding.bottom,
width: MediaQuery.of(context).size.width,
height: 60 + MediaQuery.paddingOf(context).bottom,
width: MediaQuery.sizeOf(context).width,
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).padding.bottom,
bottom: MediaQuery.paddingOf(context).bottom,
left: 16,
right: 16,
),

View File

@ -24,7 +24,7 @@ class ResponseDrawer extends StatelessWidget {
),
body: Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).padding.bottom,
bottom: MediaQuery.paddingOf(context).bottom,
),
child: const ResponsePane(),
),

View File

@ -14,7 +14,7 @@ class SettingsPage extends ConsumerWidget {
final clearingData = ref.watch(clearDataStateProvider);
var sm = ScaffoldMessenger.of(context);
final isMobile =
kIsMobile && MediaQuery.of(context).size.width < kMinWindowSize.width;
kIsMobile && MediaQuery.sizeOf(context).width < kMinWindowSize.width;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [

View File

@ -16,7 +16,7 @@ class DropdownButtonHttpMethod extends StatelessWidget {
Widget build(BuildContext context) {
final surfaceColor = Theme.of(context).colorScheme.surface;
final isMobile =
kIsMobile && MediaQuery.of(context).size.width < kMinWindowSize.width;
kIsMobile && MediaQuery.sizeOf(context).width < kMinWindowSize.width;
return DropdownButton<HTTPVerb>(
focusColor: surfaceColor,
value: method,

View File

@ -24,7 +24,7 @@ class IntroMessage extends StatelessWidget {
future: introData(),
builder: (BuildContext context, AsyncSnapshot<void> snapshot) {
final isMobile = kIsMobile &&
MediaQuery.of(context).size.width < kMinWindowSize.width;
MediaQuery.sizeOf(context).width < kMinWindowSize.width;
if (snapshot.hasError) {
return const ErrorMessage(message: "An error occured");
}

View File

@ -46,7 +46,7 @@ class _RequestPaneState extends State<RequestPane>
_controller.index = widget.tabIndex!;
}
final isMobile =
kIsMobile && MediaQuery.of(context).size.width < kMinWindowSize.width;
kIsMobile && MediaQuery.sizeOf(context).width < kMinWindowSize.width;
return Column(
children: [
isMobile

View File

@ -13,7 +13,7 @@ class TabLabel extends StatelessWidget {
@override
Widget build(BuildContext context) {
final isMobile =
kIsMobile && MediaQuery.of(context).size.width < kMinWindowSize.width;
kIsMobile && MediaQuery.sizeOf(context).width < kMinWindowSize.width;
return SizedBox(
height: isMobile ? kMobileTabHeight : kTabHeight,
child: Stack(