utilities_example
was auto-generated byhelpis_cli
The aim of this project is to provide a range of examples for the functionality provided in the utilities package, the adaptive_scaffold, and the helpis_cli.
The example has been developed and tested on PopOS 22.04
, on a physical android
device, and on the latest google-chrome-stable
from the apt
package repository on linux
.
Known issues:
- The
just_audio
implementation for linux based onmpv
has many bugs and malfunctions. - There is no way to my knowledge to change the localization of
MediaItem
s that display song information on the android system (lock screen & notifications bar)
To install and build the project you have to have already installed git, and flutter. You can find instructions on how to install those on their respected websites:
-
Clone the repo
git clone https://github.com/helpisdev/utilities_example.git
-
Change directory to
utilities_example
cd utilities_example
-
Install Flutter packages
flutter pub get
-
If you are on
linux
, downloadmpv
:sudo apt update sudo apt install -y mpv
-
Symlink the gradle.properties inside the
android
directory to run on android. For example, onlinux
run:cd android ln -s ../gradle.properties . cd ..
-
Run the project:
flutter run --flavor production
To build release instances or for other platforms check BUILD.md
The lib/main.dart
file is using the following features from utilities
, adaptive_scaffold
, and helpis_cli
util.Platform
to check the platform (web, desktop, mobile)util.usePathUrlStrategy()
to use path URLs on the webutil.ensureInitialized()
to initialize utilities dependenciesutil.PermissionHandler
to request permissions
AdaptiveScaffold
which provides a responsive layout for web, desktop and mobileGTKManager
to initialize GTK on desktop
- Initializes the caching service generated with
helpis createStore
In lib/src/configuration.dart
, the following features of utilities
and adaptive_scaffold
are being used
GoRouterAdaptiveScaffoldConfig
to configure the adaptive scaffold.AdaptiveAppBar
,AdaptiveScrollbarConfig
andNavigationRailConfig
to configure the app bar, scrollbar and navigation rail respectively.
H4
fromutilities
to style the app bar title.context.currentTheme
to get the current theme.
In lib/src/entry.dart
, the following features of utilities
, helpis_cli
, and adaptive_scaffold
are being used
util.Localizations
is used to provide locale-specific resources to the app.util.WebDragScrollBehavior()
is used as the scroll behavior for theMaterialApp
. It enables drag-to-scroll behavior for web.util.ScreenSizeProvider
is a widget used to provide the screen size to its child widget.- The
ChangeLocalization
extension is used to change the locale of aBuildContext
. It is called ascontext.changeLocale(locale)
.
storage
refers to theStorageService
which is used to cache data in the app. It is used to store the locale, theme mode, and other settings.Theming
is a widget used to provide theme data to its child widget. It uses theThemeProvider
to get the current theme.ThemeProvider
is used to manage the light and dark themes, and switch between them. It is accessed usingThemeProvider.of(context)
.
GTKLocalizations.delegate
is used to provide GTK-based localizations to the app.
- The
LocaleName
typedef
to represent a locale nameas aString
. - The
LocalizationsProvider
to provide locale information to theBuildContext
. - The
Language
enum is used to represent the supported languages in the app. It currently has two options:EN
for EnglishEL
for Greek Thelanguage
getter uses theLocalizationsProvider
to get the currently selectedLanguage
based on the locale.
- The
ScreenRoute
class is used as a base class for all app routes inlib/src/routes.dart
. It defines some common properties and methods for the routes:title()
: Returns the title for the route.builder
: Returns the widget builder for the route.
The actual app routes (like OpeningRoute
, SettingsRoute
, etc.) extend the AppRoute
which extends ScreenRoute
class and provide implementations for the title()
, builder
and extra methods defined in AppRoute
like navigate<T>()
methods.
So in summary, the ScreenRoute
class defines a common interface/contract for all app routes, and the concrete route classes implement that interface.
The lib/src/screens/opening.dart
file is using the following features from utilities
and adaptive_scaffold
snackBar()
which is used to show aSnackBar
with an action button.Breakpoint
andPredefinedBreakpoint
which are used to determine if the screen is being shown on mobile or desktop.Platform
which is used to check if the platform is mobile or desktop.
GoRouterAdaptiveScaffoldConfig
which is used to configure theAdaptiveScaffold
.GoRouterBodyConfig
which is used to configure the body of theAdaptiveScaffold
.StatelessScreen
which is the base screen class used. ExtendsScreen
.AdaptiveScaffold
which is the main scaffold widget used to handle responsiveness.
The OpeningScreen
is using these widgets and utilities to show either a desktop layout with a radio player above the scaffold, or a mobile layout with the radio player below the scaffold. It also shows a SnackBar
with an action button on desktop, and without an action button on mobile. The OpeningScreen
is also a StatefulScreenWidget
, a Screen
without the enforcement of returning a Screen
from build
, that can also hold its own state.
LoadingShimmer
, which displays a shimmering loading effect while data is loading. It is used here as a placeholder while theFutureBuilder
is waiting for the product data (mocked with a 3 second delay).FadingListView
, which is aListView
that fades items in and out as they scroll on and off screen. It is used here to display the list of products, fading them in and out smoothly.widthTransformer
, which is a utility function that calculates a width based on a percentage of the available width. It is used here to get 90% of the available width, and pass that to theLoadingShimmer
as its width.
The lib/src/screens/settings.dart
file is using the following features from utilities
and helpis_cli
LabelLarge
is used to display the text for the language switch button. It is given a maximum of 3 lines and is center aligned.BuildContext.changeLocale
is called to change the locale/language of the app. It is passed the newLanguage
to change to.StyledElevatedButton.icon
is used to create the language switch button. It displays an icon and label, and calls the onPressed method when tapped to change the language.
storage.write
is called to save the new locale's language code to cache using theStorageKey.locale.name
key.
LeadParagraph
: Used to display the product description. It is a responsive text widget that adapts its font size based on the viewport size.H2
,H3
,H4
: Used to display the product title.H3
is used on mobile,H2
on desktop.H4
is used to display the formatted product price on mobile.LabelSmall
: Used to display the product SKU (Stock Keeping Unit) on desktop.ResizableText
: Used to format and display the product price. It is a responsive text widget that adapts its font size based on the viewport size.Platform
: Used to check if the app is running on mobile or desktop and show/hide certain widgets accordingly.BuildContext.currentTheme
: Used to get the current theme and use its colors for text, containers, etc.Currency
: Represents the currency the product is priced in. Used to format the price correctly.Currency.format
: Used to format the product price according to the currency. For example, $1.99 for USD, €1.99 for EUR.
The lib/src/widgets/radio/widgets/player_screen_builder.dart
file is using the following features from utilities
and adaptive_scaffold
produceValOrNull
: This is a utility function that takes a producer function and an input value. It will call the producer function if the input value is non-null, and return the produced value. Otherwise it returnsnull
. It is used here to optionally configure anAdaptiveScaffoldConfig
if one is passed in.produceT1fromT2orNull
: This is similar toproduceValOrNull
but converts from one type to another. It is used here to optionally convert aScaffold
to aScreenScaffold
if aScaffold
is passed in.ScreenScaffold
: This wraps aScaffold
and adds aGoRouterState
. It is used so that theScaffold
can be used within theGoRouter
navigation system.Copy
interface: This is used to create a copy of theAdaptiveScrollbarConfig
with some updated values.TransparentPointer
: This is a widget that makes its child transparent to pointer events. It is used here to make theTrackPlayer
transparent to taps and drags so that when it is invisible, it let's the taps propagate the tree.ScreenWidget.generate
: This is used to generate aScreenWidget
with some default configuration. Here it is used to generate the screen widget returned by the builder function with aScreenScaffold
and configuredAdaptiveScaffoldConfig
.
AdaptiveScrollbarConfig
: This is used to configure scrollbars. Here it is used to connect the_scrollController
to the scrollbar.
The lib/src/widgets/radio/widgets/track_channel.dart
file is using the following features from utilities
- The
Base64Image
widget is used to display the channel's image. It loads the image data from a Base64-encoded string and caches the image in the system'stemp
directory. TheResizableText
widgets are used to display the channel's title and artist. They resize the text based on the available space.BodySmall
displays small body text. It is used for the channel title on mobile.BodyMedium
displays medium-sized body text. It is used for the channel title on desktop, with a max of 2 lines.LabelExtraSmall
displays extra small label text. It is used for the channel artist on mobile.LabelNormal
displays normal-sized label text. It is used for the channel artist on desktop, with a max of 2 lines. These text widgets are used to appropriately size the channel's title and artist for mobile vs desktop, and constrain the text to a maximum of 2 lines on desktop.
We try to be consistent in code style throughout our codebase and follow certain guidelines. Most of them should comply with popular standards, but some might diverge due to personal preferences and conventions. Please read more about our code style if you are considering to contribute to our products. You find general recommendations at STYLEGUIDE.md, and language-specific guidelines at the respective styleguides for each language used.