Skip to content

Commit

Permalink
Add PlatformIcons and PlatformTabScaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
aqwert committed Jan 14, 2020
1 parent b1735d1 commit 5b086ab
Show file tree
Hide file tree
Showing 14 changed files with 1,631 additions and 7 deletions.
57 changes: 56 additions & 1 deletion README.md
Expand Up @@ -37,6 +37,7 @@ Each `PlatformWidget` provides common properties directly as constructor argumen
- [PlatformIconButton](https://github.com/aqwert/flutter_platform_widgets/blob/master/README.md#platformiconbutton)
- [PlatformApp](https://github.com/aqwert/flutter_platform_widgets/blob/master/README.md#platformapp)
- [PlatformScaffold](https://github.com/aqwert/flutter_platform_widgets/blob/master/README.md#platformscaffold)
- [PlatformTabScaffold](https://github.com/aqwert/flutter_platform_widgets/blob/master/README.md#platformtabscaffold)
- [PlatformAppBar](https://github.com/aqwert/flutter_platform_widgets/blob/master/README.md#platformappbar)
- [PlatformNavBar](https://github.com/aqwert/flutter_platform_widgets/blob/master/README.md#platformnavbar)
- [PlatformAlertDialog](https://github.com/aqwert/flutter_platform_widgets/blob/master/README.md#platformalertdialog)
Expand All @@ -45,6 +46,7 @@ Each `PlatformWidget` provides common properties directly as constructor argumen
- [PlatformPageRoute](https://github.com/aqwert/flutter_platform_widgets/blob/master/README.md#platformpageroute)
- [ShowPlatformModalSheet](https://github.com/aqwert/flutter_platform_widgets/blob/master/README.md#showplatformmodalsheet)
- [PlatformProvider](https://github.com/aqwert/flutter_platform_widgets/blob/master/README.md#platformprovider)
- [PlatformIcons](https://github.com/aqwert/flutter_platform_widgets/blob/master/README.md#platformicons)

## PlatformWidget

Expand Down Expand Up @@ -246,6 +248,47 @@ return PlatformScaffold(

> Both the android and iOS builders are optional. If not provided the `Container` placeholder widget will be returned.
## PlatformTabScaffold

> Note: Using `PlatformTabScaffold` provides a more refined and flexible experience than using `PlatformScaffold`.
A Scaffold that provides the correctly hosted header (AppBar) and navigation bar (Bottom Bar) for each platform. Uses `Scaffold` for android or `CupertinoTabScaffold` for iOS with bottom tabs.

```dart
return PlatformTabScaffold(
tabController: tabController,
appBarBuilder: (_, index) => PlatformAppBar(),
bodyBuilder: (context, index) => _buildContent(index),
items: _items(context),
);
```

More more detailed example look at:

- [Basic Example](https://github.com/aqwert/flutter_platform_widgets/blob/master/example/lib/tabbed/basicTabbedPage.dart)
- [Sliver Example](https://github.com/aqwert/flutter_platform_widgets/blob/master/example/lib/tabbed/sliverTabbedPage.dart)

> Note that the use of `iosContentPadding = true` is only required if the content is being obstruced behind the appBar. `iosContentBottomPadding` is used if the content needs to be above the navBar and not go behind it. This will not have the translucent effect for iOS when these are set to `true`. If that is desirable, then the scrolling and content alignment need to be managed yourself.
#### Enhance

Extend with `WidgetBuilder` for android or iOS.

```dart
return PlatformTabScaffold(
tabController: tabController,
appBarBuilder: (_, index) => PlatformAppBar(),
bodyBuilder: (context, index) => _buildContent(index),
items: _items(context),
android: (_) => MaterialTabScaffoldData(...)
ios: (_) => CupertinoTabScaffoldData(...);
androidTabs: (_) => MaterialNavBarData(...)
iosTabs: (_) => CupertinoTabBarData(...);
);
```

> Both the android and iOS builders are optional. If not provided the `Container` placeholder widget will be returned.
## PlatformAppBar

The AppBar is the top Header bar with a title, leftside or rightside buttons. Uses `AppBar` for android or `CupertinoNavigationBar` for iOS.
Expand Down Expand Up @@ -442,7 +485,7 @@ This function is used to either display a `ModalBottomSheet` for android or `Cup
## PlatformProvider

A Provider that provides access to the functions of swicthing platforms which can be accessed from any screen.
A Provider that provides access to the functions of switching platforms which can be accessed from any screen.

Requires to be placed at the root (above MaterialApp, CupertinoApp or PlatformApp).

Expand Down Expand Up @@ -478,6 +521,18 @@ _iosUsesMaterialWidgets_

- If true it will add a Material widget above the CupertinoPageScaffold so that Material widgets can be added to the ios page. This does affect dark mode and some ios rendering so it is best to have it false (default). If you use Material widgets on the page simply add `Material(child: yourWidget)`.

## PlatformIcons

Render a Material or Cupertino looking icon

```dart
Icon(context.platformIcons.book)
//or
Icon(PlatformIcons(context).book)
```

View the [source](https://github.com/aqwert/flutter_platform_widgets/blob/master/lib/src/../../../../../../../../lib/src/platform_icons.dart) for the list of icons.

# TODO

- UI / Unit Tests.
Expand Down
213 changes: 213 additions & 0 deletions example/lib/iconPage.dart
@@ -0,0 +1,213 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';

// TODO have solid/filled for both, have normal which could be outline ios, filled android

class IconsPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return PlatformScaffold(
appBar: PlatformAppBar(title: Text('Icons')),
body: ListView(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: Text(
'Material',
textAlign: TextAlign.center,
),
),
Expanded(
child: Text(
'Cupertino',
textAlign: TextAlign.center,
),
),
],
),
_IconCompared('add', (c) => c.platformIcons.add),
_IconCompared('addCircled', (c) => c.platformIcons.addCircled),
_IconCompared(
'addCircledSolid', (c) => c.platformIcons.addCircledSolid),
_IconCompared(
'addCircledOutline', (c) => c.platformIcons.addCircledOutline),
_IconCompared('back', (c) => c.platformIcons.back),
_IconCompared(
'batteryCharging', (c) => c.platformIcons.batteryCharging),
_IconCompared('batteryFull', (c) => c.platformIcons.batteryFull),
_IconCompared('bluetooth', (c) => c.platformIcons.bluetooth),
_IconCompared('book', (c) => c.platformIcons.book),
_IconCompared('bookmark', (c) => c.platformIcons.bookmark),
_IconCompared('bookmarkSolid', (c) => c.platformIcons.bookmarkSolid),
_IconCompared(
'bookmarkOutline', (c) => c.platformIcons.bookmarkOutline),
_IconCompared('brightness', (c) => c.platformIcons.brightness),
_IconCompared(
'brightnessSolid', (c) => c.platformIcons.brightnessSolid),
_IconCompared('checkMark', (c) => c.platformIcons.checkMark),
_IconCompared(
'checkMarkCircled', (c) => c.platformIcons.checkMarkCircled),
_IconCompared('checkMarkCircledSolid',
(c) => c.platformIcons.checkMarkCircledSolid),
_IconCompared('checkMarkCircledOutline',
(c) => c.platformIcons.checkMarkCircledOutline),
_IconCompared('clear', (c) => c.platformIcons.clear),
_IconCompared('collections', (c) => c.platformIcons.collections),
_IconCompared(
'collectionsSolid', (c) => c.platformIcons.collectionsSolid),
_IconCompared(
'conversationBubble', (c) => c.platformIcons.conversationBubble),
_IconCompared('conversationBubbleOutline',
(c) => c.platformIcons.conversationBubbleOutline),
_IconCompared('create', (c) => c.platformIcons.create),
_IconCompared('delete', (c) => c.platformIcons.delete),
_IconCompared('deleteSolid', (c) => c.platformIcons.deleteSolid),
_IconCompared('deleteOutline', (c) => c.platformIcons.deleteOutline),
_IconCompared('downArrow', (c) => c.platformIcons.downArrow),
_IconCompared('ellipsis', (c) => c.platformIcons.ellipsis),
_IconCompared('folder', (c) => c.platformIcons.folder),
_IconCompared('folderOpen', (c) => c.platformIcons.folderOpen),
_IconCompared('folderSolid', (c) => c.platformIcons.folderSolid),
_IconCompared('forward', (c) => c.platformIcons.forward),
_IconCompared('fullscreen', (c) => c.platformIcons.fullscreen),
_IconCompared(
'fullscreenExit', (c) => c.platformIcons.fullscreenExit),
_IconCompared(
'gameController', (c) => c.platformIcons.gameController),
_IconCompared('gameControllerSolid',
(c) => c.platformIcons.gameControllerSolid),
_IconCompared('group', (c) => c.platformIcons.group),
_IconCompared('groupSolid', (c) => c.platformIcons.groupSolid),
_IconCompared('home', (c) => c.platformIcons.home),
_IconCompared('info', (c) => c.platformIcons.info),
_IconCompared('leftChevron', (c) => c.platformIcons.leftChevron),
_IconCompared('location', (c) => c.platformIcons.location),
_IconCompared('locationSolid', (c) => c.platformIcons.locationSolid),
_IconCompared('loop', (c) => c.platformIcons.loop),
_IconCompared('mail', (c) => c.platformIcons.mail),
_IconCompared('mailSolid', (c) => c.platformIcons.mailSolid),
_IconCompared('mailOutline', (c) => c.platformIcons.mailOutline),
_IconCompared('mic', (c) => c.platformIcons.mic),
_IconCompared('micSolid', (c) => c.platformIcons.micSolid),
_IconCompared('micOutline', (c) => c.platformIcons.micOutline),
_IconCompared('micOff', (c) => c.platformIcons.micOff),
_IconCompared('musicNote', (c) => c.platformIcons.musicNote),
_IconCompared('padLock', (c) => c.platformIcons.padLock),
_IconCompared('padlockSolid', (c) => c.platformIcons.padlockSolid),
_IconCompared(
'padlockOutline', (c) => c.platformIcons.padlockOutline),
_IconCompared('pause', (c) => c.platformIcons.pause),
_IconCompared('person', (c) => c.platformIcons.person),
_IconCompared('personSolid', (c) => c.platformIcons.personSolid),
_IconCompared('personOutline', (c) => c.platformIcons.personOutline),
_IconCompared('personAdd', (c) => c.platformIcons.personAdd),
_IconCompared(
'personAddSolid', (c) => c.platformIcons.personAddSolid),
_IconCompared('phone', (c) => c.platformIcons.phone),
_IconCompared('phoneSolid', (c) => c.platformIcons.phoneSolid),
_IconCompared('photoCamera', (c) => c.platformIcons.photoCamera),
_IconCompared(
'photoCameraSolid', (c) => c.platformIcons.photoCameraSolid),
_IconCompared('playArrow', (c) => c.platformIcons.playArrow),
_IconCompared(
'playArrowSolid', (c) => c.platformIcons.playArrowSolid),
_IconCompared('refresh', (c) => c.platformIcons.refresh),
_IconCompared('refreshBold', (c) => c.platformIcons.refreshBold),
_IconCompared('reply', (c) => c.platformIcons.reply),
_IconCompared('replyAll', (c) => c.platformIcons.replyAll),
_IconCompared('rightChevron', (c) => c.platformIcons.rightChevron),
_IconCompared('search', (c) => c.platformIcons.search),
_IconCompared('settings', (c) => c.platformIcons.settings),
_IconCompared('settingsSolid', (c) => c.platformIcons.settingsSolid),
_IconCompared('share', (c) => c.platformIcons.share),
_IconCompared('shareSolid', (c) => c.platformIcons.shareSolid),
_IconCompared('shoppingCart', (c) => c.platformIcons.shoppingCart),
_IconCompared('shuffle', (c) => c.platformIcons.shuffle),
_IconCompared('switchCamera', (c) => c.platformIcons.switchCamera),
_IconCompared(
'switchCameraSolid', (c) => c.platformIcons.switchCameraSolid),
_IconCompared('tag', (c) => c.platformIcons.tag),
_IconCompared('tagSolid', (c) => c.platformIcons.tagSolid),
_IconCompared('tagOutline', (c) => c.platformIcons.tagOutline),
_IconCompared('train', (c) => c.platformIcons.train),
_IconCompared('upArrow', (c) => c.platformIcons.upArrow),
_IconCompared('videoCamera', (c) => c.platformIcons.videoCamera),
_IconCompared(
'videoCameraSolid', (c) => c.platformIcons.videoCameraSolid),
_IconCompared('volumnDown', (c) => c.platformIcons.volumnDown),
_IconCompared('volumnMute', (c) => c.platformIcons.volumnMute),
_IconCompared('volumnnUp', (c) => c.platformIcons.volumnnUp),
_IconCompared('volumnOff', (c) => c.platformIcons.volumnOff),
],
),
);
}
}

class _IconCompared extends StatelessWidget {
_IconCompared(this.title, this.icon);

final String title;
final IconData Function(BuildContext context) icon;

@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.only(top: 8),
child: Stack(
children: <Widget>[
Row(
children: <Widget>[
Expanded(child: material((context) => icon(context))),
Expanded(child: cupertino((context) => icon(context))),
],
),
Align(
alignment: Alignment.center,
child: Text(title),
),
],
),
);
}

Widget material(IconData Function(BuildContext context) icon) {
return _ThemedPlatform(
TargetPlatform.android,
(context) => Icon(
icon(context),
),
);
}

Widget cupertino(IconData Function(BuildContext context) icon) {
return _ThemedPlatform(
TargetPlatform.iOS,
(context) => Icon(
icon(context),
),
);
}
}

class _ThemedPlatform extends StatelessWidget {
_ThemedPlatform(this.platform, this.builder);

final TargetPlatform platform;
final WidgetBuilder builder;

@override
Widget build(BuildContext context) {
final data = Theme.of(context).copyWith(platform: platform);

return Theme(
data: data,
child: Builder(
builder: (context) => builder(context),
),
);
}
}
30 changes: 26 additions & 4 deletions example/lib/main.dart
Expand Up @@ -9,8 +9,12 @@ import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';

import 'iconPage.dart';
import 'listViewHeaderPage.dart';
import 'listViewPage.dart';
import 'tabbed/basicTabbedPage.dart';
import 'tabbed/originalTabbedPage.dart';
import 'tabbed/sliverTabbedPage.dart';
import 'tabbedPage.dart';

void main() => runApp(Main());
Expand Down Expand Up @@ -219,19 +223,37 @@ class LandingPageState extends State<LandingPage> {
SectionHeader(title: '5. Navigation'),
PlatformButton(
child: PlatformText('Open Tabbed Page'),
onPressed: () => _openPage((_) => new TabbedPage()),
onPressed: () => _openPage((_) => TabbedPage()),
),
PlatformButton(
child: PlatformText('Open Basic Tabbed Page'),
onPressed: () => _openPage((_) => BasicTabbedPage()),
),
PlatformButton(
child: PlatformText('Open Sliver Tabbed Page'),
onPressed: () => _openPage((_) => SliverTabbedPage()),
),
PlatformButton(
child: PlatformText('Open Original Tabbed Page'),
onPressed: () => _openPage((_) => OriginalTabbedPage()),
),
Divider(),
SectionHeader(title: '6. Icons'),
PlatformButton(
child: PlatformText('Open Icons Page'),
onPressed: () => _openPage((_) => IconsPage()),
),
Divider(),
SectionHeader(title: '6. Advanced'),
SectionHeader(title: '7. Advanced'),
PlatformButton(
child: PlatformText('Page with ListView'),
onPressed: () => _openPage((_) => new ListViewPage()),
onPressed: () => _openPage((_) => ListViewPage()),
),
PlatformWidget(
android: (_) => Container(), //this is for iOS only
ios: (_) => PlatformButton(
child: PlatformText('iOS Page with Colored Header'),
onPressed: () => _openPage((_) => new ListViewHeaderPage()),
onPressed: () => _openPage((_) => ListViewHeaderPage()),
),
),
],
Expand Down

0 comments on commit 5b086ab

Please sign in to comment.