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(
textScaleFactor: 1.0,
size: Size(
deviceSize.width / 16 * 9,
deviceSize.height * 9 / 16,
deviceSize.height,
),
),

View File

@ -9,21 +9,33 @@ import 'package:didvan/models/view/action_sheet_data.dart';
import 'package:didvan/models/view/alert_data.dart';
import 'package:didvan/views/widgets/didvan/button.dart';
import 'package:didvan/views/widgets/didvan/text.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
class ActionSheetUtils {
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 {
await showDialog(
barrierDismissible: false,
context: context,
builder: (context) => Padding(
padding: EdgeInsets.symmetric(
horizontal: MediaQuery.of(context).size.width / 3,
builder: (context) => Center(
child: SizedBox(
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 {
await showModalBottomSheet(
constraints: BoxConstraints(
maxWidth: mediaQueryData.size.width,
),
backgroundColor: Colors.transparent,
isScrollControlled: true,
context: context,
@ -168,7 +183,8 @@ class ActionSheetUtils {
shape: const RoundedRectangleBorder(
borderRadius: DesignConfig.mediumBorderRadius,
),
child: Padding(
child: Container(
width: mediaQueryData.size.width * 0.8,
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisSize: MainAxisSize.min,

View File

@ -60,10 +60,10 @@ class CategoryItem extends StatelessWidget {
child: Container(
width: !_useWebMobileLayout(context)
? _width(context) / 2
: ds.width / 5,
: ds.width / 7,
height: !_useWebMobileLayout(context)
? _width(context) / 2
: ds.width / 5,
: ds.width / 7,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,
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/constants/app_icons.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/utils/action_sheet.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_state.dart';
@ -275,70 +277,77 @@ class _PlayerNavBar extends StatelessWidget {
}
final state = context.read<StudioState>();
showModalBottomSheet(
constraints: BoxConstraints(
maxWidth: ActionSheetUtils.mediaQueryData.size.width,
),
backgroundColor: Colors.transparent,
context: context,
isScrollControlled: true,
builder: (context) => ChangeNotifierProvider<StudioState>.value(
value: state,
child: Consumer<StudioDetailsState>(
builder: (context, state, child) => ExpandableBottomSheet(
key: sheetKey,
background: Align(
alignment: Alignment.bottomCenter,
child: Container(
height: MediaQuery.of(context).size.height * 0.7,
color: Theme.of(context).colorScheme.surface,
builder: (context, state, child) => MediaQuery(
data: ActionSheetUtils.mediaQueryData,
child: ExpandableBottomSheet(
key: sheetKey,
background: Align(
alignment: Alignment.bottomCenter,
child: Container(
height: MediaQuery.of(context).size.height * 0.7,
color: Theme.of(context).colorScheme.surface,
),
),
),
persistentHeader: GestureDetector(
onVerticalDragUpdate: (details) {
if (details.delta.dy > 10) {
Navigator.of(context).pop();
}
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
AudioPlayerWidget(
podcast: MediaService.currentPodcast!,
),
Container(
width: MediaQuery.of(context).size.width,
color: Theme.of(context).colorScheme.surface,
child: Column(
children: [
DidvanIconButton(
size: 32,
icon: DidvanIcons.angle_up_regular,
onPressed: () {
if (!isExpanded) {
sheetKey.currentState?.expand();
isExpanded = true;
} else {
isExpanded = false;
sheetKey.currentState?.contract();
}
},
),
const SizedBox(height: 16),
],
persistentHeader: GestureDetector(
onVerticalDragUpdate: (details) {
if (details.delta.dy > 10) {
Navigator.of(context).pop();
}
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
AudioPlayerWidget(
podcast: MediaService.currentPodcast!,
),
),
],
Container(
width: MediaQuery.of(context).size.width,
color: Theme.of(context).colorScheme.surface,
child: Column(
children: [
DidvanIconButton(
size: 32,
icon: DidvanIcons.angle_up_regular,
onPressed: () {
if (!isExpanded) {
sheetKey.currentState?.expand();
isExpanded = true;
} else {
isExpanded = false;
sheetKey.currentState?.contract();
}
},
),
const SizedBox(height: 16),
],
),
),
],
),
),
),
expandableContent: state.appState == AppState.busy
? Container(
height: MediaQuery.of(context).size.height / 2,
alignment: Alignment.center,
child: SpinKitSpinningLines(
color: Theme.of(context).colorScheme.primary,
expandableContent: state.appState == AppState.busy
? Container(
height: MediaQuery.of(context).size.height / 2,
alignment: Alignment.center,
child: SpinKitSpinningLines(
color: Theme.of(context).colorScheme.primary,
),
)
: StudioDetailsWidget(
onMarkChanged: (id, value) => context
.read<StudioState>()
.changeMark(id, value, true),
),
)
: StudioDetailsWidget(
onMarkChanged: (id, value) =>
context.read<StudioState>().changeMark(id, value, true),
),
),
),
),
),

View File

@ -235,31 +235,34 @@ class _DidvanPageViewState extends State<DidvanPageView> {
borderRadius: DesignConfig.lowBorderRadius,
),
alignment: Alignment.center,
child: DidvanCard(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
children: [
Icon(
DidvanIcons.info_circle_solid,
color: Theme.of(context).colorScheme.primary,
),
const SizedBox(width: 8),
DidvanText(
element!.text,
style: Theme.of(context).textTheme.subtitle2,
),
],
),
const SizedBox(height: 8),
DidvanText(href.split('-').last),
const SizedBox(height: 16),
const DidvanButton(
title: 'بستن',
onPressed: ActionSheetUtils.pop,
),
],
child: SizedBox(
width: ActionSheetUtils.mediaQueryData.size.width,
child: DidvanCard(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
children: [
Icon(
DidvanIcons.info_circle_solid,
color: Theme.of(context).colorScheme.primary,
),
const SizedBox(width: 8),
DidvanText(
element!.text,
style: Theme.of(context).textTheme.subtitle2,
),
],
),
const SizedBox(height: 8),
DidvanText(href.split('-').last),
const SizedBox(height: 16),
const DidvanButton(
title: 'بستن',
onPressed: ActionSheetUtils.pop,
),
],
),
),
),
),

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<!--
<head>
<!--
If you are serving your web app in a path other than the root, change the
href value below to reflect the base path you are serving from.
@ -14,70 +14,78 @@
This is a placeholder for base href that will be replaced by the value of
the `--base-href` argument provided to `flutter build`.
-->
<base href="$FLUTTER_BASE_HREF">
<base href="$FLUTTER_BASE_HREF" />
<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="A new Flutter project.">
<meta charset="UTF-8" />
<meta content="IE=Edge" http-equiv="X-UA-Compatible" />
<meta name="description" content="A new Flutter project." />
<!-- iOS meta tags & icons -->
<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-title" content="didvan">
<link rel="apple-touch-icon" href="icons/icon.png">
<!-- iOS meta tags & icons -->
<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-title" content="didvan" />
<link rel="apple-touch-icon" href="icons/icon.png" />
<!-- Favicon -->
<link rel="icon" type="image/png" href="favicon.png"/>
<!-- Favicon -->
<link rel="icon" type="image/png" href="favicon.png" />
<title>Didvan</title>
<link rel="manifest" href="manifest.json">
<style>
.container {
width: 100vw;
height: 100vh;
display: flex; /* Default Axis is X*/
justify-content: center; /* Main Axis */
align-items: center; /* Cross Axis */
}
.indicator{
width: 50vw;
}
</style>
</head>
<body style="overflow: hidden">
<div id="loading_indicator" class="container">
<img class="indicator" src="./assets/lib/assets/animations/loading.gif" />
</div>
<!-- This script installs service_worker.js to provide PWA functionality to
<title>Didvan</title>
<link rel="manifest" href="manifest.json" />
<style>
.container {
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.indicator {
width: 50vw;
}
@media only screen and (min-width: 600px) {
.indicator {
width: 25vw;
}
}
</style>
</head>
<body style="overflow: hidden">
<div id="loading_indicator" class="container">
<img class="indicator" src="./assets/lib/assets/animations/loading.gif" />
</div>
<!-- This script installs service_worker.js to provide PWA functionality to
application. For more information, see:
https://developers.google.com/web/fundamentals/primers/service-workers -->
<script>
var serviceWorkerVersion = null;
var scriptLoaded = false;
function loadMainDartJs() {
if (scriptLoaded) {
return;
<script>
var serviceWorkerVersion = null;
var scriptLoaded = false;
function loadMainDartJs() {
if (scriptLoaded) {
return;
}
scriptLoaded = true;
var scriptTag = document.createElement("script");
scriptTag.src = `main.dart.js?version=${Math.random()}`;
scriptTag.type = "application/javascript";
document.body.append(scriptTag);
}
scriptLoaded = true;
var scriptTag = document.createElement('script');
scriptTag.src = `main.dart.js?version=${Math.random()}`;
scriptTag.type = 'application/javascript';
document.body.append(scriptTag);
}
if ('serviceWorker' in navigator) {
// Service workers are supported. Use them.
window.addEventListener('load', function () {
// Wait for registration to finish before dropping the <script> tag.
// Otherwise, the browser will load the script multiple times,
// potentially different versions.
var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
navigator.serviceWorker.register(serviceWorkerUrl)
.then((reg) => {
if ("serviceWorker" in navigator) {
// Service workers are supported. Use them.
window.addEventListener("load", function () {
// Wait for registration to finish before dropping the <script> tag.
// Otherwise, the browser will load the script multiple times,
// potentially different versions.
var serviceWorkerUrl =
"flutter_service_worker.js?v=" + serviceWorkerVersion;
navigator.serviceWorker.register(serviceWorkerUrl).then((reg) => {
function waitForActivation(serviceWorker) {
serviceWorker.addEventListener('statechange', () => {
if (serviceWorker.state == 'activated') {
console.log('Installed new service worker.');
serviceWorker.addEventListener("statechange", () => {
if (serviceWorker.state == "activated") {
console.log("Installed new service worker.");
loadMainDartJs();
}
});
@ -89,39 +97,39 @@
} else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
// When the app updates the serviceWorkerVersion changes, so we
// need to ask the service worker to update.
console.log('New service worker available.');
console.log("New service worker available.");
reg.update();
waitForActivation(reg.installing);
} else {
// Existing service worker is still good.
console.log('Loading app from service worker.');
console.log("Loading app from service worker.");
loadMainDartJs();
}
});
// If service worker doesn't succeed in a reasonable amount of time,
// fallback to plaint <script> tag.
setTimeout(() => {
if (!scriptLoaded) {
console.warn(
'Failed to load app from service worker. Falling back to plain <script> tag.',
);
loadMainDartJs();
}
}, 4000);
});
} else {
// Service workers not supported. Just drop the <script> tag.
loadMainDartJs();
}
window.onload = function () {
// If service worker doesn't succeed in a reasonable amount of time,
// fallback to plaint <script> tag.
setTimeout(() => {
if (!scriptLoaded) {
console.warn(
"Failed to load app from service worker. Falling back to plain <script> tag."
);
loadMainDartJs();
}
}, 4000);
});
} else {
// Service workers not supported. Just drop the <script> tag.
loadMainDartJs();
}
window.onload = function () {
setTimeout(function () {
var loadingIndicator = document.getElementById("loading_indicator");
if (loadingIndicator) {
loadingIndicator.remove();
}
}, 10000);
};
</script>
</body>
};
</script>
</body>
</html>