Skip to content

Commit

Permalink
feat: add platform tabbar and platform property
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Oct 27, 2022
1 parent d9115e5 commit d68f1a9
Show file tree
Hide file tree
Showing 6 changed files with 509 additions and 134 deletions.
269 changes: 141 additions & 128 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,149 +56,162 @@ class _MyHomePageState extends State<MyHomePage> {
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
body: PlatformTabView(
body: {
PlatformTab(
label: "Widgets",
icon: const Icon(Icons.collections_bookmark_rounded),
): Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
PlatformFilledButton(
child: Text('Android'),
onPressed: () => widget.onChange(TargetPlatform.android),
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
PlatformFilledButton(
child: const Text('Android'),
onPressed: () => widget.onChange(TargetPlatform.android),
),
PlatformFilledButton(
child: const Text('iOS'),
onPressed: () => widget.onChange(TargetPlatform.iOS),
),
PlatformFilledButton(
child: const Text('Linux'),
onPressed: () => widget.onChange(TargetPlatform.linux),
),
PlatformFilledButton(
child: const Text('MacOS'),
onPressed: () => widget.onChange(TargetPlatform.macOS),
),
PlatformFilledButton(
child: const Text('Windows'),
onPressed: () => widget.onChange(TargetPlatform.windows),
),
],
),
PlatformFilledButton(
child: Text('iOS'),
onPressed: () => widget.onChange(TargetPlatform.iOS),
const Text(
'You have pushed the button this many times:',
),
PlatformFilledButton(
child: Text('Linux'),
onPressed: () => widget.onChange(TargetPlatform.linux),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
PlatformFilledButton(
child: Text('MacOS'),
onPressed: () => widget.onChange(TargetPlatform.macOS),
child: const Text("Filled Button"),
onPressed: () {
setState(() {
_counter++;
});
},
),
PlatformFilledButton(
child: Text('Windows'),
onPressed: () => widget.onChange(TargetPlatform.windows),
PlatformTextButton(
child: const Text("Text Button"),
onPressed: () {
setState(() {
_counter++;
});
},
),
],
),
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
PlatformFilledButton(
child: const Text("Filled Button"),
onPressed: () {
setState(() {
_counter++;
});
},
),
PlatformTextButton(
child: const Text("Text Button"),
onPressed: () {
setState(() {
_counter++;
});
},
),
PlatformIconButton(
icon: const Icon(Icons.star_border_rounded),
onPressed: () {},
),
PlatformSwitch(
value: checked,
onChanged: (value) {
setState(() {
checked = value;
});
},
activeThumbColor: Colors.red,
activeTrackColor: Colors.red[800],
inactiveTrackColor: Colors.white,
inactiveThumbColor: Colors.green,
),
const PlatformTextField(
padding: EdgeInsets.all(8),
placeholder: "Placeholder",
label: "Label",
backgroundColor: Colors.blue,
focusedBackgroundColor: Colors.amber,
),
PlatformDropDownMenu(
onChanged: (value) {},
dropdownColor: Colors.grey,
elevation: 20,
items: [
PlatformDropDownMenuItem(
child: const Text("LOL"),
value: "LOL",
PlatformIconButton(
icon: const Icon(Icons.star_border_rounded),
onPressed: () {},
),
PlatformDropDownMenuItem(
child: const Text("Cool"),
value: "Cool",
PlatformSwitch(
value: checked,
onChanged: (value) {
setState(() {
checked = value;
});
},
activeThumbColor: Colors.red,
activeTrackColor: Colors.red[800],
inactiveTrackColor: Colors.white,
inactiveThumbColor: Colors.green,
),
PlatformDropDownMenuItem(
child: const Text("Foul"),
value: "Foul",
const PlatformTextField(
padding: EdgeInsets.all(8),
placeholder: "Placeholder",
label: "Label",
backgroundColor: Colors.blue,
focusedBackgroundColor: Colors.amber,
),
],
),
PlatformListTile(
title: const Text("Title"),
subtitle: const Text("Subtitle"),
leading: const Icon(Icons.star_border_rounded),
trailing: const Icon(Icons.star_border_rounded),
onTap: () {
print("Tapped");
},
onLongPress: () {
print("Long Pressed");
},
),
PlatformListTile(
title: const Text("Title"),
subtitle: const Text("Subtitle"),
leading: const Icon(Icons.accessibility_outlined),
trailing: const Icon(Icons.airline_seat_legroom_reduced_outlined),
onTap: () {
print("Tapped");
},
onLongPress: () {
print("Long Pressed");
},
),
PlatformPopupMenuButton<String>(
items: [
PlatformPopupMenuItem(
value: "lol",
child: const Text("LOL"),
PlatformDropDownMenu(
onChanged: (value) {},
dropdownColor: Colors.grey,
elevation: 20,
items: [
PlatformDropDownMenuItem(
child: const Text("LOL"),
value: "LOL",
),
PlatformDropDownMenuItem(
child: const Text("Cool"),
value: "Cool",
),
PlatformDropDownMenuItem(
child: const Text("Foul"),
value: "Foul",
),
],
),
PlatformListTile(
title: const Text("Title"),
subtitle: const Text("Subtitle"),
leading: const Icon(Icons.star_border_rounded),
trailing: const Icon(Icons.star_border_rounded),
onTap: () {
print("Tapped");
},
onLongPress: () {
print("Long Pressed");
},
),
PlatformListTile(
title: const Text("Title"),
subtitle: const Text("Subtitle"),
leading: const Icon(Icons.accessibility_outlined),
trailing:
const Icon(Icons.airline_seat_legroom_reduced_outlined),
onTap: () {
print("Tapped");
},
onLongPress: () {
print("Long Pressed");
},
),
PlatformPopupMenuItem(
value: "lmao",
child: const Text("LMAO"),
PlatformPopupMenuButton<String>(
items: [
PlatformPopupMenuItem(
value: "lol",
child: const Text("LOL"),
),
PlatformPopupMenuItem(
value: "lmao",
child: const Text("LMAO"),
),
PlatformPopupMenuItem(
value: "ftw",
child: const Text("FTW"),
),
],
color: Colors.grey,
child: const Icon(Icons.more_horiz_rounded),
),
PlatformPopupMenuItem(
value: "ftw",
child: const Text("FTW"),
PlatformTooltip(
message:
"Really Wonderful ${Theme.of(context).platform.name}",
child: const Text("Hover/Long-Press for Tooltip"),
),
const Text("Hover/Long-Press for Popup Menu"),
],
color: Colors.grey,
child: const Icon(Icons.more_horiz_rounded),
),
PlatformTooltip(
message: "Really Wonderful ${Theme.of(context).platform.name}",
child: const Text("Hover/Long-Press for Tooltip"),
),
const Text("Hover/Long-Press for Popup Menu"),
],
),
),
PlatformTab(
label: "Apple's HIG",
icon: const Icon(Icons.format_align_justify),
): Container(),
},
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
Expand Down
2 changes: 2 additions & 0 deletions lib/platform_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ export 'src/platform_drop_down_menu.dart';
export 'src/platform_list_tile.dart';
export 'src/platform_tooltip.dart';
export 'src/platform_popup_menu_button.dart';
export 'src/platform_tab_view.dart';
export 'src/platform_property.dart';
29 changes: 25 additions & 4 deletions lib/src/platform_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@ class PlatformApp extends StatelessWidget with PlatformMixin<Widget> {
themeMode: themeMode,
color: color,
locale: locale,
localizationsDelegates: localizationsDelegates,
localizationsDelegates: [
...(localizationsDelegates ?? []),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
FluentUI.FluentLocalizations.delegate,
],
localeListResolutionCallback: localeListResolutionCallback,
localeResolutionCallback: localeResolutionCallback,
supportedLocales: supportedLocales,
Expand Down Expand Up @@ -151,7 +157,13 @@ class PlatformApp extends StatelessWidget with PlatformMixin<Widget> {
theme: iosTheme,
color: color,
locale: locale,
localizationsDelegates: localizationsDelegates,
localizationsDelegates: [
...(localizationsDelegates ?? []),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
FluentUI.FluentLocalizations.delegate,
],
localeListResolutionCallback: localeListResolutionCallback,
localeResolutionCallback: localeResolutionCallback,
supportedLocales: supportedLocales,
Expand Down Expand Up @@ -192,7 +204,13 @@ class PlatformApp extends StatelessWidget with PlatformMixin<Widget> {
themeMode: themeMode,
color: color,
locale: locale,
localizationsDelegates: localizationsDelegates,
localizationsDelegates: [
...(localizationsDelegates ?? []),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
FluentUI.FluentLocalizations.delegate,
],
localeListResolutionCallback: localeListResolutionCallback,
localeResolutionCallback: localeResolutionCallback,
supportedLocales: supportedLocales,
Expand Down Expand Up @@ -229,7 +247,10 @@ class PlatformApp extends StatelessWidget with PlatformMixin<Widget> {
locale: locale,
localizationsDelegates: [
...(localizationsDelegates ?? []),
FluentLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
FluentUI.FluentLocalizations.delegate,
],
supportedLocales: [
...supportedLocales,
Expand Down
Loading

0 comments on commit d68f1a9

Please sign in to comment.