utilities_examplewas 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_audioimplementation for linux based onmpvhas many bugs and malfunctions. - There is no way to my knowledge to change the localization of
MediaItems 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_examplecd 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
androiddirectory to run on android. For example, onlinuxrun: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.Platformto check the platform (web, desktop, mobile)util.usePathUrlStrategy()to use path URLs on the webutil.ensureInitialized()to initialize utilities dependenciesutil.PermissionHandlerto request permissions
AdaptiveScaffoldwhich provides a responsive layout for web, desktop and mobileGTKManagerto 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
GoRouterAdaptiveScaffoldConfigto configure the adaptive scaffold.AdaptiveAppBar,AdaptiveScrollbarConfigandNavigationRailConfigto configure the app bar, scrollbar and navigation rail respectively.
H4fromutilitiesto style the app bar title.context.currentThemeto get the current theme.
In lib/src/entry.dart, the following features of utilities, helpis_cli, and adaptive_scaffold are being used
util.Localizationsis 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.ScreenSizeProvideris a widget used to provide the screen size to its child widget.- The
ChangeLocalizationextension is used to change the locale of aBuildContext. It is called ascontext.changeLocale(locale).
storagerefers to theStorageServicewhich is used to cache data in the app. It is used to store the locale, theme mode, and other settings.Themingis a widget used to provide theme data to its child widget. It uses theThemeProviderto get the current theme.ThemeProvideris used to manage the light and dark themes, and switch between them. It is accessed usingThemeProvider.of(context).
GTKLocalizations.delegateis used to provide GTK-based localizations to the app.
- The
LocaleNametypedefto represent a locale nameas aString. - The
LocalizationsProviderto provide locale information to theBuildContext. - The
Languageenum is used to represent the supported languages in the app. It currently has two options:ENfor EnglishELfor Greek Thelanguagegetter uses theLocalizationsProviderto get the currently selectedLanguagebased on the locale.
- The
ScreenRouteclass 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 aSnackBarwith an action button.BreakpointandPredefinedBreakpointwhich are used to determine if the screen is being shown on mobile or desktop.Platformwhich is used to check if the platform is mobile or desktop.
GoRouterAdaptiveScaffoldConfigwhich is used to configure theAdaptiveScaffold.GoRouterBodyConfigwhich is used to configure the body of theAdaptiveScaffold.StatelessScreenwhich is the base screen class used. ExtendsScreen.AdaptiveScaffoldwhich 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 theFutureBuilderis waiting for the product data (mocked with a 3 second delay).FadingListView, which is aListViewthat 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 theLoadingShimmeras its width.
The lib/src/screens/settings.dart file is using the following features from utilities and helpis_cli
LabelLargeis used to display the text for the language switch button. It is given a maximum of 3 lines and is center aligned.BuildContext.changeLocaleis called to change the locale/language of the app. It is passed the newLanguageto change to.StyledElevatedButton.iconis 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.writeis called to save the new locale's language code to cache using theStorageKey.locale.namekey.
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.H3is used on mobile,H2on desktop.H4is 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 anAdaptiveScaffoldConfigif one is passed in.produceT1fromT2orNull: This is similar toproduceValOrNullbut converts from one type to another. It is used here to optionally convert aScaffoldto aScreenScaffoldif aScaffoldis passed in.ScreenScaffold: This wraps aScaffoldand adds aGoRouterState. It is used so that theScaffoldcan be used within theGoRouternavigation system.Copyinterface: This is used to create a copy of theAdaptiveScrollbarConfigwith some updated values.TransparentPointer: This is a widget that makes its child transparent to pointer events. It is used here to make theTrackPlayertransparent 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 aScreenWidgetwith some default configuration. Here it is used to generate the screen widget returned by the builder function with aScreenScaffoldand configuredAdaptiveScaffoldConfig.
AdaptiveScrollbarConfig: This is used to configure scrollbars. Here it is used to connect the_scrollControllerto the scrollbar.
The lib/src/widgets/radio/widgets/track_channel.dart file is using the following features from utilities
- The
Base64Imagewidget 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'stempdirectory. TheResizableTextwidgets are used to display the channel's title and artist. They resize the text based on the available space.BodySmalldisplays small body text. It is used for the channel title on mobile.BodyMediumdisplays medium-sized body text. It is used for the channel title on desktop, with a max of 2 lines.LabelExtraSmalldisplays extra small label text. It is used for the channel artist on mobile.LabelNormaldisplays 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.