InAppWebView
unknown
dart
2 years ago
5.6 kB
9
Indexable
import 'dart:developer';
import 'package:base_architecture/core/shared_widgets/ACScaffold.dart';
import 'package:base_architecture/core/shared_widgets/ac_appbar_widget.dart';
import 'package:base_architecture/core/shared_widgets/share_box_widget.dart';
import 'package:base_architecture/presentation/notifiers/podcast_notifier/podcast_notifier.dart';
import 'package:base_architecture/presentation/notifiers/theme_notifier.dart';
import 'package:base_architecture/presentation/pages/main/main_page.dart';
import 'package:dartz/dartz_unsafe.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_uxcam/flutter_uxcam.dart';
import 'package:provider/provider.dart';
class LivePodcastPage extends StatefulWidget {
const LivePodcastPage({Key? key}) : super(key: key);
@override
State<LivePodcastPage> createState() => _LivePodcastPageState();
}
class _LivePodcastPageState extends State<LivePodcastPage> {
late PodcastNotifier _podcastNotifier;
@override
void initState() {
mixpanel?.track('Live podcast Page viewed');
mixpanel?.track('View live podcast');
FlutterUxcam.logEvent('Live podcast Page viewed');
FlutterUxcam.logEvent('View live podcast');
_podcastNotifier = Provider.of<PodcastNotifier>(context, listen: false);
_podcastNotifier.getLivePodcast();
super.initState();
}
@override
Widget build(BuildContext context) {
Size mediaQuery = MediaQuery.of(context).size;
ThemeNotifier themeNotifier = Provider.of<ThemeNotifier>(
context,
listen: true,
);
PodcastNotifier podcastNotifier =
Provider.of<PodcastNotifier>(context, listen: true);
return ACScaffold(
backgroundColor: themeNotifier.getTheme().primaryColor,
appBar: _appBar(podcastNotifier),
body: _mainBody(mediaQuery, themeNotifier, podcastNotifier),
);
}
Widget _mainBody(
Size mediaQuery,
ThemeNotifier themeNotifier,
PodcastNotifier podcastNotifier,
) =>
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20),
child: Column(
children: <Widget>[
_liveContainer(mediaQuery, podcastNotifier),
_liveHoster(themeNotifier, podcastNotifier),
],
),
);
Widget _liveHoster(
ThemeNotifier themeNotifier, PodcastNotifier podcastNotifier) =>
Column(
children: <Widget>[
Container(
padding: const EdgeInsets.only(
top: 35,
bottom: 8,
),
child: Text(
'${podcastNotifier.livePodcastData?.data?.name ?? ''}',
style: themeNotifier.getTheme().textTheme.headline2!.copyWith(
fontSize: 22,
color: themeNotifier.getTheme().hoverColor,
),
textAlign: TextAlign.center,
),
),
RichText(
textAlign: TextAlign.center,
text: TextSpan(
text: '',
style: themeNotifier.getTheme().textTheme.headline2!.copyWith(
fontSize: 18,
color: themeNotifier.getTheme().hintColor,
),
children: [
TextSpan(
text: '${podcastNotifier.livePodcastData?.data?.description}',
style: themeNotifier.getTheme().textTheme.headline2!.copyWith(
fontSize: 18,
color: themeNotifier.getTheme().hintColor,
),
),
],
),
),
],
);
Widget _liveContainer(
Size mediaQuery,
PodcastNotifier podcastNotifier,
) {
String? path = podcastNotifier.livePodcastData?.data?.podcastLink;
RegExp exp = RegExp(r'[\u0621-\u064a-\u061b\u060c|@\$]');
String result = path!.replaceAll(exp, '');
return Container(
height: mediaQuery.height * 0.28,
child: Center(
child: InAppWebView(
initialUrlRequest: URLRequest(
url: Uri.parse(
Uri.dataFromString(
'<html style="margin:0;padding:0"><meta name="viewport"content="width=device-width"> <iframe width="100%" height="100%" allowfullscreen${result}</html>',
mimeType: 'text/html',
).toString(),
),
),
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
mediaPlaybackRequiresUserGesture: false,
),
),
),
),
);
}
PreferredSizeWidget? _appBar(
PodcastNotifier podcastNotifier,
) =>
ACAppBar(
hasBack: true,
title: 'Podcast details'.tr(),
leadingWidth: 65,
toolbarHeight: 80,
actions: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: ShareBoxWidget(
showText: false,
title: podcastNotifier.livePodcastData?.data?.name ?? '',
desc: podcastNotifier.livePodcastData?.data?.description ?? '',
image: 'image',
type: 'live_podcast',
id: 0,
),
),
],
onBack: () {
Navigator.of(navigatorKey.currentContext!).pop();
mixpanel?.track('Pressed back ');
FlutterUxcam.logEvent('Pressed back ');
},
);
}
Editor is loading...