From 8fa83fd44d6751fb8ea435a6b83a1583fb102cf6 Mon Sep 17 00:00:00 2001 From: Aldrin Zigmund Cortez Velasco Date: Fri, 13 Oct 2023 16:03:55 +0800 Subject: [PATCH] minor code improvements --- lib/main.dart | 7 ++---- lib/pages/channelpage-iptv.dart | 16 +++++++----- lib/pages/home pages/channellistpage.dart | 12 ++++----- lib/pages/home pages/contactpage.dart | 30 +++++++---------------- lib/pages/home pages/favoritespage.dart | 8 +++--- lib/pages/loadingpage.dart | 6 ++--- 6 files changed, 34 insertions(+), 45 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index b5e443a..582ab8d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -8,11 +8,8 @@ void main() { // WidgetsFlutterBinding.ensureInitialized(); // MobileAds.instance.initialize(); - runApp(MaterialApp( + runApp(const MaterialApp( title: "Digilog TV", - initialRoute: '/', - routes: { - '/': (context) => const LoadingPage(), - }, + home: LoadingPage(), )); } diff --git a/lib/pages/channelpage-iptv.dart b/lib/pages/channelpage-iptv.dart index b9e7d3d..3f6a617 100644 --- a/lib/pages/channelpage-iptv.dart +++ b/lib/pages/channelpage-iptv.dart @@ -27,6 +27,15 @@ class _ChannelPageIPTVState extends State { bool _appBarVisibility = true; + _setupVideoPlayerController() { + _videoPlayerController = VideoPlayerController.networkUrl( + Uri.parse(storage.channels.channelList[index].link)) + ..initialize().then((_) { + setState(() {}); + _videoPlayerController.play(); + }); + } + _hideUnhideAppBar() { setState(() { _appBarVisibility = !_appBarVisibility; @@ -50,12 +59,7 @@ class _ChannelPageIPTVState extends State { index = widget.index; storage = widget.storage; WakelockPlus.enable(); - _videoPlayerController = VideoPlayerController.networkUrl( - Uri.parse(storage.channels.channelList[index].link)) - ..initialize().then((_) { - setState(() {}); - _videoPlayerController.play(); - }); + _setupVideoPlayerController(); } @override diff --git a/lib/pages/home pages/channellistpage.dart b/lib/pages/home pages/channellistpage.dart index 7113bd3..d97a06e 100644 --- a/lib/pages/home pages/channellistpage.dart +++ b/lib/pages/home pages/channellistpage.dart @@ -51,7 +51,7 @@ class _ChannelListPageState extends State { // )..load(); // } - favoriteIcon(String channelName) { + _favoriteIcon(String channelName) { if (!storage.favoritedChannels.contains(channelName)) { return Icon( Icons.star_border, @@ -65,7 +65,7 @@ class _ChannelListPageState extends State { } } - favoriteChange(int index) async { + _favoriteChange(int index) async { if (storage.favoritedChannels .contains(storage.channels.channelList[index].channelName)) { setState(() { @@ -81,7 +81,7 @@ class _ChannelListPageState extends State { await storage.saveChanges(); } - goToChannel(int index) { + _goToChannel(int index) { if (storage.channels.channelList[index].source == Source.iptv) { goToChannelPageIPTV(context: context, index: index, storage: storage); } else { @@ -128,7 +128,7 @@ class _ChannelListPageState extends State { return Padding( padding: const EdgeInsets.all(3.0), child: GestureDetector( - onTap: () => goToChannel(index), + onTap: () => _goToChannel(index), child: Card( child: Padding( padding: const EdgeInsets.all(18.0), @@ -151,11 +151,11 @@ class _ChannelListPageState extends State { )), ), GestureDetector( - onTap: () => favoriteChange(index), + onTap: () => _favoriteChange(index), child: Padding( padding: const EdgeInsets.symmetric(horizontal: 9.0), - child: favoriteIcon(storage + child: _favoriteIcon(storage .channels.channelList[index].channelName), ), ), diff --git a/lib/pages/home pages/contactpage.dart b/lib/pages/home pages/contactpage.dart index 3d405d8..a3d7d1c 100644 --- a/lib/pages/home pages/contactpage.dart +++ b/lib/pages/home pages/contactpage.dart @@ -1,28 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; class ContactPage extends StatelessWidget { const ContactPage({super.key}); - copyBitcoinAddress(BuildContext context) { - Clipboard.setData(const ClipboardData( - text: 'bc1qruus6vnxrww6pqac3hvg6vsepmqv8d66dwjm59')); - ScaffoldMessenger.of(context).showSnackBar(const SnackBar( - content: Text("Bitcoin Address copied to clipboard."), - duration: Duration(seconds: 2), - )); - } - - copyMoneroAddress(BuildContext context) { - Clipboard.setData(const ClipboardData( - text: - '86cQoPfKTJ2bRfGH5Ts2kzaXCRcVRiX8CUHKc9xmeUmQ8YM8Uzk9S97T5gQaqYu58C9wuFK7opDH7cM9EJyR4V5LAq9RGv4')); - ScaffoldMessenger.of(context).showSnackBar(const SnackBar( - content: Text("Monero Address copied to clipboard."), - duration: Duration(seconds: 2), - )); - } - @override Widget build(BuildContext context) { return Center( @@ -50,11 +30,19 @@ class ContactPage extends StatelessWidget { const Padding( padding: EdgeInsets.fromLTRB(18.0, 36.0, 18.0, 18.0), child: Text( - 'You have downloaded the ad-supported version of this app from Google Play. An ad-free version is available on GitHub. Other ads are provided by their respective TV news channels.', + 'You have downloaded the ad-free version of this app. Other ads are provided by their respective TV news channels.', style: TextStyle(fontSize: 18.0), textAlign: TextAlign.center, ), ), + // const Padding( + // padding: EdgeInsets.fromLTRB(18.0, 36.0, 18.0, 18.0), + // child: Text( + // 'You have downloaded the ad-supported version of this app from Google Play. An ad-free version is available on GitHub. Other ads are provided by their respective TV news channels.', + // style: TextStyle(fontSize: 18.0), + // textAlign: TextAlign.center, + // ), + // ), ], ), ), diff --git a/lib/pages/home pages/favoritespage.dart b/lib/pages/home pages/favoritespage.dart index 0631f84..b7e5b84 100644 --- a/lib/pages/home pages/favoritespage.dart +++ b/lib/pages/home pages/favoritespage.dart @@ -51,7 +51,7 @@ class _FavoritesPageState extends State { // )..load(); // } - favoriteChange(int index) async { + _favoriteChange(int index) async { setState(() { storage.favoritedChannels .remove(storage.arrangedChannelList[index].channelName); @@ -60,7 +60,7 @@ class _FavoritesPageState extends State { await storage.saveChanges(); } - goToChannel(int index) { + _goToChannel(int index) { if (storage.arrangedChannelList[index].source == Source.iptv) { goToChannelPageIPTV(context: context, index: storage.channels.getIndexByChannelName(storage.arrangedChannelList[index].channelName), storage: storage); } else { @@ -109,7 +109,7 @@ class _FavoritesPageState extends State { return Padding( padding: const EdgeInsets.all(3.0), child: GestureDetector( - onTap: () => goToChannel(index), + onTap: () => _goToChannel(index), child: Card( child: Padding( padding: const EdgeInsets.all(18.0), @@ -134,7 +134,7 @@ class _FavoritesPageState extends State { )), ), GestureDetector( - onTap: () => favoriteChange(index), + onTap: () => _favoriteChange(index), child: Padding( padding: const EdgeInsets.symmetric( horizontal: 9.0), diff --git a/lib/pages/loadingpage.dart b/lib/pages/loadingpage.dart index 0909631..c5b4e1c 100644 --- a/lib/pages/loadingpage.dart +++ b/lib/pages/loadingpage.dart @@ -15,7 +15,7 @@ class _LoadingPageState extends State { final StorageProvider storage = StorageProvider(); final FormattingProvider formatingProvider = FormattingProvider(); - startup() async { + _startup() async { await storage.initialize(); Future.delayed(const Duration(seconds: 1), () async { goToHomePage( @@ -28,7 +28,7 @@ class _LoadingPageState extends State { @override void initState() { super.initState(); - startup(); + _startup(); } @override @@ -40,7 +40,7 @@ class _LoadingPageState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( - padding: EdgeInsets.all(9.0), + padding: const EdgeInsets.all(9.0), child: Image.asset('assets/icons/icon.png')), const Padding( padding: EdgeInsets.all(9.0),