responsive web version

This commit is contained in:
MohammadTaha Basiri 2022-05-01 20:11:58 +04:30
parent 41be81e532
commit d9c930c494
6 changed files with 201 additions and 165 deletions

View File

@ -195,7 +195,7 @@ class RouteGenerator {
data: MediaQuery.of(context).copyWith( data: MediaQuery.of(context).copyWith(
textScaleFactor: 1.0, textScaleFactor: 1.0,
size: Size( size: Size(
deviceSize.width / 16 * 9, deviceSize.height * 9 / 16,
deviceSize.height, deviceSize.height,
), ),
), ),

View File

@ -9,22 +9,34 @@ import 'package:didvan/models/view/action_sheet_data.dart';
import 'package:didvan/models/view/alert_data.dart'; import 'package:didvan/models/view/alert_data.dart';
import 'package:didvan/views/widgets/didvan/button.dart'; import 'package:didvan/views/widgets/didvan/button.dart';
import 'package:didvan/views/widgets/didvan/text.dart'; import 'package:didvan/views/widgets/didvan/text.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:rive/rive.dart'; import 'package:rive/rive.dart';
class ActionSheetUtils { class ActionSheetUtils {
static late BuildContext context; static late BuildContext context;
static MediaQueryData get mediaQueryData {
final ds = MediaQuery.of(context).size;
double width = ds.width;
final shortestSide = ds.shortestSide;
final bool useMobileLayout = shortestSide < 600;
if (kIsWeb && !useMobileLayout) {
width = ds.height * 9 / 16;
}
return MediaQuery.of(context).copyWith(size: Size(width, ds.height));
}
static Future<void> showLogoLoadingIndicator() async { static Future<void> showLogoLoadingIndicator() async {
await showDialog( await showDialog(
barrierDismissible: false, barrierDismissible: false,
context: context, context: context,
builder: (context) => Padding( builder: (context) => Center(
padding: EdgeInsets.symmetric( child: SizedBox(
horizontal: MediaQuery.of(context).size.width / 3, width: mediaQueryData.size.width * 0.4,
),
child: RiveAnimation.asset(Assets.logoLoadingAnimation), child: RiveAnimation.asset(Assets.logoLoadingAnimation),
), ),
),
); );
} }
@ -76,6 +88,9 @@ class ActionSheetUtils {
static Future<void> showBottomSheet({required ActionSheetData data}) async { static Future<void> showBottomSheet({required ActionSheetData data}) async {
await showModalBottomSheet( await showModalBottomSheet(
constraints: BoxConstraints(
maxWidth: mediaQueryData.size.width,
),
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
isScrollControlled: true, isScrollControlled: true,
context: context, context: context,
@ -168,7 +183,8 @@ class ActionSheetUtils {
shape: const RoundedRectangleBorder( shape: const RoundedRectangleBorder(
borderRadius: DesignConfig.mediumBorderRadius, borderRadius: DesignConfig.mediumBorderRadius,
), ),
child: Padding( child: Container(
width: mediaQueryData.size.width * 0.8,
padding: const EdgeInsets.all(24.0), padding: const EdgeInsets.all(24.0),
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,

View File

@ -60,10 +60,10 @@ class CategoryItem extends StatelessWidget {
child: Container( child: Container(
width: !_useWebMobileLayout(context) width: !_useWebMobileLayout(context)
? _width(context) / 2 ? _width(context) / 2
: ds.width / 5, : ds.width / 7,
height: !_useWebMobileLayout(context) height: !_useWebMobileLayout(context)
? _width(context) / 2 ? _width(context) / 2
: ds.width / 5, : ds.width / 7,
decoration: BoxDecoration( decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface, color: Theme.of(context).colorScheme.surface,
boxShadow: DesignConfig.defaultShadow, boxShadow: DesignConfig.defaultShadow,

View File

@ -3,7 +3,9 @@ import 'package:didvan/config/design_config.dart';
import 'package:didvan/config/theme_data.dart'; import 'package:didvan/config/theme_data.dart';
import 'package:didvan/constants/app_icons.dart'; import 'package:didvan/constants/app_icons.dart';
import 'package:didvan/models/enums.dart'; import 'package:didvan/models/enums.dart';
import 'package:didvan/models/view/action_sheet_data.dart';
import 'package:didvan/services/media/media.dart'; import 'package:didvan/services/media/media.dart';
import 'package:didvan/utils/action_sheet.dart';
import 'package:didvan/views/home/studio/studio_details/studio_details_state.dart'; import 'package:didvan/views/home/studio/studio_details/studio_details_state.dart';
import 'package:didvan/views/home/studio/studio_details/widgets/studio_details_widget.dart'; import 'package:didvan/views/home/studio/studio_details/widgets/studio_details_widget.dart';
import 'package:didvan/views/home/studio/studio_state.dart'; import 'package:didvan/views/home/studio/studio_state.dart';
@ -275,13 +277,18 @@ class _PlayerNavBar extends StatelessWidget {
} }
final state = context.read<StudioState>(); final state = context.read<StudioState>();
showModalBottomSheet( showModalBottomSheet(
constraints: BoxConstraints(
maxWidth: ActionSheetUtils.mediaQueryData.size.width,
),
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
context: context, context: context,
isScrollControlled: true, isScrollControlled: true,
builder: (context) => ChangeNotifierProvider<StudioState>.value( builder: (context) => ChangeNotifierProvider<StudioState>.value(
value: state, value: state,
child: Consumer<StudioDetailsState>( child: Consumer<StudioDetailsState>(
builder: (context, state, child) => ExpandableBottomSheet( builder: (context, state, child) => MediaQuery(
data: ActionSheetUtils.mediaQueryData,
child: ExpandableBottomSheet(
key: sheetKey, key: sheetKey,
background: Align( background: Align(
alignment: Alignment.bottomCenter, alignment: Alignment.bottomCenter,
@ -336,8 +343,10 @@ class _PlayerNavBar extends StatelessWidget {
), ),
) )
: StudioDetailsWidget( : StudioDetailsWidget(
onMarkChanged: (id, value) => onMarkChanged: (id, value) => context
context.read<StudioState>().changeMark(id, value, true), .read<StudioState>()
.changeMark(id, value, true),
),
), ),
), ),
), ),

View File

@ -235,6 +235,8 @@ class _DidvanPageViewState extends State<DidvanPageView> {
borderRadius: DesignConfig.lowBorderRadius, borderRadius: DesignConfig.lowBorderRadius,
), ),
alignment: Alignment.center, alignment: Alignment.center,
child: SizedBox(
width: ActionSheetUtils.mediaQueryData.size.width,
child: DidvanCard( child: DidvanCard(
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
@ -263,6 +265,7 @@ class _DidvanPageViewState extends State<DidvanPageView> {
), ),
), ),
), ),
),
); );
} else { } else {
launch(href); launch(href);

View File

@ -14,36 +14,44 @@
This is a placeholder for base href that will be replaced by the value of This is a placeholder for base href that will be replaced by the value of
the `--base-href` argument provided to `flutter build`. the `--base-href` argument provided to `flutter build`.
--> -->
<base href="$FLUTTER_BASE_HREF"> <base href="$FLUTTER_BASE_HREF" />
<meta charset="UTF-8"> <meta charset="UTF-8" />
<meta content="IE=Edge" http-equiv="X-UA-Compatible"> <meta content="IE=Edge" http-equiv="X-UA-Compatible" />
<meta name="description" content="A new Flutter project."> <meta name="description" content="A new Flutter project." />
<!-- iOS meta tags & icons --> <!-- iOS meta tags & icons -->
<meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black"> <meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="apple-mobile-web-app-title" content="didvan"> <meta name="apple-mobile-web-app-title" content="didvan" />
<link rel="apple-touch-icon" href="icons/icon.png"> <link rel="apple-touch-icon" href="icons/icon.png" />
<!-- Favicon --> <!-- Favicon -->
<link rel="icon" type="image/png" href="favicon.png" /> <link rel="icon" type="image/png" href="favicon.png" />
<title>Didvan</title> <title>Didvan</title>
<link rel="manifest" href="manifest.json"> <link rel="manifest" href="manifest.json" />
<style> <style>
.container { .container {
width: 100vw; width: 100vw;
height: 100vh; height: 100vh;
display: flex; /* Default Axis is X*/ display: flex;
justify-content: center; /* Main Axis */ justify-content: center;
align-items: center; /* Cross Axis */ align-items: center;
} }
.indicator { .indicator {
width: 50vw; width: 50vw;
} }
@media only screen and (min-width: 600px) {
.indicator {
width: 25vw;
}
}
</style> </style>
</head> </head>
<body style="overflow: hidden"> <body style="overflow: hidden">
<div id="loading_indicator" class="container"> <div id="loading_indicator" class="container">
<img class="indicator" src="./assets/lib/assets/animations/loading.gif" /> <img class="indicator" src="./assets/lib/assets/animations/loading.gif" />
@ -59,25 +67,25 @@
return; return;
} }
scriptLoaded = true; scriptLoaded = true;
var scriptTag = document.createElement('script'); var scriptTag = document.createElement("script");
scriptTag.src = `main.dart.js?version=${Math.random()}`; scriptTag.src = `main.dart.js?version=${Math.random()}`;
scriptTag.type = 'application/javascript'; scriptTag.type = "application/javascript";
document.body.append(scriptTag); document.body.append(scriptTag);
} }
if ('serviceWorker' in navigator) { if ("serviceWorker" in navigator) {
// Service workers are supported. Use them. // Service workers are supported. Use them.
window.addEventListener('load', function () { window.addEventListener("load", function () {
// Wait for registration to finish before dropping the <script> tag. // Wait for registration to finish before dropping the <script> tag.
// Otherwise, the browser will load the script multiple times, // Otherwise, the browser will load the script multiple times,
// potentially different versions. // potentially different versions.
var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion; var serviceWorkerUrl =
navigator.serviceWorker.register(serviceWorkerUrl) "flutter_service_worker.js?v=" + serviceWorkerVersion;
.then((reg) => { navigator.serviceWorker.register(serviceWorkerUrl).then((reg) => {
function waitForActivation(serviceWorker) { function waitForActivation(serviceWorker) {
serviceWorker.addEventListener('statechange', () => { serviceWorker.addEventListener("statechange", () => {
if (serviceWorker.state == 'activated') { if (serviceWorker.state == "activated") {
console.log('Installed new service worker.'); console.log("Installed new service worker.");
loadMainDartJs(); loadMainDartJs();
} }
}); });
@ -89,12 +97,12 @@
} else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) { } else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
// When the app updates the serviceWorkerVersion changes, so we // When the app updates the serviceWorkerVersion changes, so we
// need to ask the service worker to update. // need to ask the service worker to update.
console.log('New service worker available.'); console.log("New service worker available.");
reg.update(); reg.update();
waitForActivation(reg.installing); waitForActivation(reg.installing);
} else { } else {
// Existing service worker is still good. // Existing service worker is still good.
console.log('Loading app from service worker.'); console.log("Loading app from service worker.");
loadMainDartJs(); loadMainDartJs();
} }
}); });
@ -104,7 +112,7 @@
setTimeout(() => { setTimeout(() => {
if (!scriptLoaded) { if (!scriptLoaded) {
console.warn( console.warn(
'Failed to load app from service worker. Falling back to plain <script> tag.', "Failed to load app from service worker. Falling back to plain <script> tag."
); );
loadMainDartJs(); loadMainDartJs();
} }