- Cupertino Widegts is iOS-style app implementing iOS design language based on Apple's Human Interface Guidelines only for Mobile apps; due to font licensing not same feel on Android
is another option to Material Widgets for iOS, Android, Web
-
flutter create cupertino_appto initiate -
lib/main.dart to import
cupertino widgetpackage; also import service library for platform services like clipboard and device orientation -
lib/styles.dart to centrally and separately define text/color styling
-
lib/app.dart to add
CupertinoStoreAppclass
returning
CupertinoAppinstance providing theming, navigation, text-direction and other defaultswith
CupertinoStoreHomePageinstance as homepage
- Cupertino package provides 2 kind page scaffolds.
CupertinoPageScaffoldsupports single pages and accepts Cupertino style widgets and visual flow.
CupertinoTabScaffoldsupports pages with tabs.
- Update pubspec.yaml for shrine_images to manage image assets, provider for dependency injection, intl for internationalization, cupertino_icons for default icons
add an image asset in pubspec.yaml as well
-
Final app to have 3 tabs:
Product List,Product SearchandShopping Cart -
Cupertino tab has a separate scaffold because on iOS, bottom tab is commonly persistent above nested routes instead of inside pages.
-
lib/app.dart to be updated
Use
CupertinoTabScaffoldwith 3 tabs to be returned withCupertinoStoreHomePage; also with data-source providing item list.With
tabBarmentioning 3 BottomNavigationBarItem populated CupertinoTabBar; addtabBuilderwith switch returning a CupertinoTabView for each tab.CupertinoTabView returning CupertinoPageScaffold.
- add stub class for product list content via lib/product_list_tab.dart, returns
Consumerfromproviderpackage assisting with state-management
2 types of navigation bar on iOS, common short static type and tall scrollable large title type; latter implemented inside
CustomScrollViewwith aCupertinoSliverNavigationBarwidget
-
add search page stub, create lib/search_tab.dart a state-ful widget
-
add shopping cart page stub lib/shopping_cart_tab.dart, maintains list of purchases and customer's info
-
update lib/app.dart to import new tab widgets
-
for common data to be shared across multiple screens, need a simple way to flow data to each objects that need it; scoped_model package allows it
-
define data model used to pass data from parent widget to its descendants, wrapping model in
ScopedModelwidget allows that -
add lib/model/product.dart for product data source; each instance of
Coffeeclass describes a product for sale -
add product repository at lib/model/products_repository.dart for sale; with mock data better loaded via an API
-
now we can define lib/model/app_state_model.dart with
AppStateModelclass providing methods for accessing data
add method to access cart total, a list for selected products to purchase, for shipping cost, and more
- add
app_state_model.dartto wireAppStateModelat top of widget tree usingChangeNotifierProvider
-
to display products for sale in product list tab using lib/product_row_item.dart
-
import it in
product_list_tab.dart, update it to show coffees usingSliverSafeArea -
CupertinoSliverNavigationBaraccounts for notch,SliverSafeAreanotch left true for right and left for horizontal view if required
-
add lib/search_bar.dart with
SearchBarclass to handle search, with custom style to converge changes over iOS -
update lib/search_tab.dart to import
provider,app_state_model,product_row_item,search_barandstyles
overrde
initStateanddispose, add_onTextChangedand_buildSearchBoxmethods to_SearchTabStatethen replace
CustomScrollViewin it's build to sendDecoratedBoxutilizing_buildSearchBox
- update lib/shopping_cart_tab.dart to add private methods for building name, email and location fields with
_buildSliverChildBuilderDelegateforSliverSafeAreaforCustomScrollView
-
using
CupertinoDatePickerin shopping cart so user can select a preferred date -
update lib/shopping_cart_tab.dart's
_buildSliverChildBuilderDelegatewith_buildDateAndTimePicker
-
import
model/product.dart; add_currencyFormatto_ShoppingCartTabState -
add a product index and cart display under
default
