From 1df87c61b6ffc34d1459385efc258de16b0b110e Mon Sep 17 00:00:00 2001 From: Fahad Saleem Date: Fri, 13 Jan 2023 13:07:53 +0500 Subject: [PATCH 1/2] iconData to Widget --- example/lib/main.dart | 32 +++-- example/lib/main_demo.dart | 204 ++++++++++++++++++++++++----- example/lib/main_example.dart | 10 +- example/lib/main_outside_list.dart | 98 +++++++++++--- example/pubspec.lock | 31 ++--- lib/src/actions.dart | 8 +- pubspec.lock | 28 ++-- test/actions_test.dart | 4 +- test/dismissible_pane_test.dart | 85 +++++++++--- test/slidable_test.dart | 144 ++++++++++++++++---- 10 files changed, 504 insertions(+), 140 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 97415b3b..65205869 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -34,14 +34,18 @@ class MyApp extends StatelessWidget { onPressed: doNothing, backgroundColor: Color(0xFFFE4A49), foregroundColor: Colors.white, - icon: Icons.delete, + icon: SizedBox( + child: Icon(Icons.delete), + ), label: 'Delete', ), SlidableAction( onPressed: doNothing, backgroundColor: Color(0xFF21B7CA), foregroundColor: Colors.white, - icon: Icons.share, + icon: SizedBox( + child: Icon(Icons.share), + ), label: 'Share', ), ], @@ -57,14 +61,18 @@ class MyApp extends StatelessWidget { onPressed: doNothing, backgroundColor: Color(0xFF7BC043), foregroundColor: Colors.white, - icon: Icons.archive, + icon: SizedBox( + child: Icon(Icons.archive), + ), label: 'Archive', ), SlidableAction( onPressed: doNothing, backgroundColor: Color(0xFF0392CF), foregroundColor: Colors.white, - icon: Icons.save, + icon: SizedBox( + child: Icon(Icons.save), + ), label: 'Save', ), ], @@ -90,14 +98,18 @@ class MyApp extends StatelessWidget { onPressed: doNothing, backgroundColor: Color(0xFFFE4A49), foregroundColor: Colors.white, - icon: Icons.delete, + icon: SizedBox( + child: Icon(Icons.delete), + ), label: 'Delete', ), SlidableAction( onPressed: doNothing, backgroundColor: Color(0xFF21B7CA), foregroundColor: Colors.white, - icon: Icons.share, + icon: SizedBox( + child: Icon(Icons.share), + ), label: 'Share', ), ], @@ -114,14 +126,18 @@ class MyApp extends StatelessWidget { onPressed: doNothing, backgroundColor: Color(0xFF7BC043), foregroundColor: Colors.white, - icon: Icons.archive, + icon: SizedBox( + child: Icon(Icons.archive), + ), label: 'Archive', ), SlidableAction( onPressed: doNothing, backgroundColor: Color(0xFF0392CF), foregroundColor: Colors.white, - icon: Icons.save, + icon: SizedBox( + child: Icon(Icons.save), + ), label: 'Save', ), ], diff --git a/example/lib/main_demo.dart b/example/lib/main_demo.dart index afb1b97d..7797be20 100644 --- a/example/lib/main_demo.dart +++ b/example/lib/main_demo.dart @@ -58,15 +58,32 @@ class _MyHomePageState extends State { closeThreshold: 0.4, motion: BehindMotion(), children: [ - SlideAction(color: Colors.green, icon: Icons.share), - SlideAction(color: Colors.amber, icon: Icons.delete), + SlideAction( + color: Colors.green, + icon: SizedBox( + child: Icon(Icons.share), + )), + SlideAction( + color: Colors.amber, + icon: SizedBox( + child: Icon(Icons.delete), + )), ], ), endActionPane: const ActionPane( motion: BehindMotion(), children: [ - SlideAction(color: Colors.red, icon: Icons.delete_forever), - SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2), + SlideAction( + color: Colors.red, + icon: SizedBox( + child: Icon(Icons.delete), + )), + SlideAction( + color: Colors.blue, + icon: SizedBox( + child: Icon(Icons.alarm), + ), + flex: 2), ], ), child: const Tile(color: Colors.grey, text: 'hello'), @@ -79,15 +96,32 @@ class _MyHomePageState extends State { startActionPane: const ActionPane( motion: StretchMotion(), children: [ - SlideAction(color: Colors.green, icon: Icons.share), - SlideAction(color: Colors.amber, icon: Icons.delete), + SlideAction( + color: Colors.green, + icon: SizedBox( + child: Icon(Icons.share), + )), + SlideAction( + color: Colors.amber, + icon: SizedBox( + child: Icon(Icons.delete), + )), ], ), endActionPane: const ActionPane( motion: StretchMotion(), children: [ - SlideAction(color: Colors.red, icon: Icons.delete_forever), - SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 3), + SlideAction( + color: Colors.red, + icon: SizedBox( + child: Icon(Icons.delete), + )), + SlideAction( + color: Colors.blue, + icon: SizedBox( + child: Icon(Icons.alarm), + ), + flex: 3), ], ), child: const Tile(color: Colors.pink, text: 'hello 2'), @@ -98,15 +132,32 @@ class _MyHomePageState extends State { startActionPane: const ActionPane( motion: ScrollMotion(), children: [ - SlideAction(color: Colors.green, icon: Icons.share), - SlideAction(color: Colors.amber, icon: Icons.delete), + SlideAction( + color: Colors.green, + icon: SizedBox( + child: Icon(Icons.share), + )), + SlideAction( + color: Colors.amber, + icon: SizedBox( + child: Icon(Icons.delete), + )), ], ), endActionPane: const ActionPane( motion: ScrollMotion(), children: [ - SlideAction(color: Colors.red, icon: Icons.delete_forever), - SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2), + SlideAction( + color: Colors.red, + icon: SizedBox( + child: Icon(Icons.delete), + )), + SlideAction( + color: Colors.blue, + icon: SizedBox( + child: Icon(Icons.alarm), + ), + flex: 2), ], ), child: const Tile(color: Colors.yellow, text: 'hello 3'), @@ -152,15 +203,32 @@ class _MyHomePageState extends State { }, ), children: const [ - SlideAction(color: Colors.green, icon: Icons.share), - SlideAction(color: Colors.amber, icon: Icons.delete), + SlideAction( + color: Colors.green, + icon: SizedBox( + child: Icon(Icons.share), + )), + SlideAction( + color: Colors.amber, + icon: SizedBox( + child: Icon(Icons.delete), + )), ], ), endActionPane: const ActionPane( motion: DrawerMotion(), children: [ - SlideAction(color: Colors.red, icon: Icons.delete_forever), - SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2), + SlideAction( + color: Colors.red, + icon: SizedBox( + child: Icon(Icons.delete), + )), + SlideAction( + color: Colors.blue, + icon: SizedBox( + child: Icon(Icons.alarm), + ), + flex: 2), ], ), child: const Tile(color: Colors.lime, text: 'hello 4'), @@ -171,15 +239,32 @@ class _MyHomePageState extends State { startActionPane: const ActionPane( motion: BehindMotion(), children: [ - SlideAction(color: Colors.green, icon: Icons.share), - SlideAction(color: Colors.amber, icon: Icons.delete), + SlideAction( + color: Colors.green, + icon: SizedBox( + child: Icon(Icons.share), + )), + SlideAction( + color: Colors.amber, + icon: SizedBox( + child: Icon(Icons.delete), + )), ], ), endActionPane: const ActionPane( motion: BehindMotion(), children: [ - SlideAction(color: Colors.red, icon: Icons.delete_forever), - SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2), + SlideAction( + color: Colors.red, + icon: SizedBox( + child: Icon(Icons.delete), + )), + SlideAction( + color: Colors.blue, + icon: SizedBox( + child: Icon(Icons.alarm), + ), + flex: 2), ], ), child: const Tile(color: Colors.grey, text: 'hello'), @@ -190,15 +275,32 @@ class _MyHomePageState extends State { startActionPane: const ActionPane( motion: BehindMotion(), children: [ - SlideAction(color: Colors.green, icon: Icons.share), - SlideAction(color: Colors.amber, icon: Icons.delete), + SlideAction( + color: Colors.green, + icon: SizedBox( + child: Icon(Icons.share), + )), + SlideAction( + color: Colors.amber, + icon: SizedBox( + child: Icon(Icons.delete), + )), ], ), endActionPane: const ActionPane( motion: BehindMotion(), children: [ - SlideAction(color: Colors.red, icon: Icons.delete_forever), - SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2), + SlideAction( + color: Colors.red, + icon: SizedBox( + child: Icon(Icons.delete), + )), + SlideAction( + color: Colors.blue, + icon: SizedBox( + child: Icon(Icons.alarm), + ), + flex: 2), ], ), child: const Tile(color: Colors.grey, text: 'hello'), @@ -209,15 +311,32 @@ class _MyHomePageState extends State { startActionPane: const ActionPane( motion: BehindMotion(), children: [ - SlideAction(color: Colors.green, icon: Icons.share), - SlideAction(color: Colors.amber, icon: Icons.delete), + SlideAction( + color: Colors.green, + icon: SizedBox( + child: Icon(Icons.share), + )), + SlideAction( + color: Colors.amber, + icon: SizedBox( + child: Icon(Icons.delete), + )), ], ), endActionPane: const ActionPane( motion: BehindMotion(), children: [ - SlideAction(color: Colors.red, icon: Icons.delete_forever), - SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2), + SlideAction( + color: Colors.red, + icon: SizedBox( + child: Icon(Icons.delete), + )), + SlideAction( + color: Colors.blue, + icon: SizedBox( + child: Icon(Icons.alarm), + ), + flex: 2), ], ), child: const Tile(color: Colors.grey, text: 'hello'), @@ -228,15 +347,32 @@ class _MyHomePageState extends State { startActionPane: const ActionPane( motion: BehindMotion(), children: [ - SlideAction(color: Colors.green, icon: Icons.share), - SlideAction(color: Colors.amber, icon: Icons.delete), + SlideAction( + color: Colors.green, + icon: SizedBox( + child: Icon(Icons.share), + )), + SlideAction( + color: Colors.amber, + icon: SizedBox( + child: Icon(Icons.delete), + )), ], ), endActionPane: const ActionPane( motion: BehindMotion(), children: [ - SlideAction(color: Colors.red, icon: Icons.delete_forever), - SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2), + SlideAction( + color: Colors.red, + icon: SizedBox( + child: Icon(Icons.delete), + )), + SlideAction( + color: Colors.blue, + icon: SizedBox( + child: Icon(Icons.alarm), + ), + flex: 2), ], ), child: const Tile(color: Colors.grey, text: 'hello'), @@ -257,7 +393,7 @@ class SlideAction extends StatelessWidget { }) : super(key: key); final Color color; - final IconData icon; + final Widget icon; final int flex; @override @@ -291,7 +427,7 @@ class Tile extends StatelessWidget { return ActionTypeListener( child: GestureDetector( onTap: () { - print('$text'); + print(text); }, onLongPress: () => Slidable.of(context)!.openEndActionPane(), child: Container( diff --git a/example/lib/main_example.dart b/example/lib/main_example.dart index c782adf3..bb785e6a 100644 --- a/example/lib/main_example.dart +++ b/example/lib/main_example.dart @@ -10,12 +10,16 @@ void main() { const actions = [ SlideAction( color: Color(0xFFFE4A49), - icon: Icons.delete, + icon: SizedBox( + child: Icon(Icons.delete), + ), label: 'Delete', ), SlideAction( color: Color(0xFF21B7CA), - icon: Icons.share, + icon: SizedBox( + child: Icon(Icons.share), + ), label: 'Share', ), ]; @@ -207,7 +211,7 @@ class SlideAction extends StatelessWidget { }) : super(key: key); final Color color; - final IconData icon; + final Widget icon; final int flex; final String label; diff --git a/example/lib/main_outside_list.dart b/example/lib/main_outside_list.dart index cc5ede90..b2e05583 100644 --- a/example/lib/main_outside_list.dart +++ b/example/lib/main_outside_list.dart @@ -56,17 +56,32 @@ class _MyHomePageState extends State { closeThreshold: 0.4, motion: BehindMotion(), children: [ - SlideAction(color: Colors.green, icon: Icons.share), - SlideAction(color: Colors.amber, icon: Icons.delete), + SlideAction( + color: Colors.green, + icon: SizedBox( + child: Icon(Icons.share), + )), + SlideAction( + color: Colors.amber, + icon: SizedBox( + child: Icon(Icons.delete), + )), ], ), endActionPane: const ActionPane( motion: BehindMotion(), children: [ SlideAction( - color: Colors.red, icon: Icons.delete_forever), + color: Colors.red, + icon: SizedBox( + child: Icon(Icons.delete), + )), SlideAction( - color: Colors.blue, icon: Icons.alarm, flex: 2), + color: Colors.blue, + icon: SizedBox( + child: Icon(Icons.alarm), + ), + flex: 2), ], ), child: const Tile(color: Colors.grey, text: 'hello'), @@ -81,15 +96,32 @@ class _MyHomePageState extends State { startActionPane: const ActionPane( motion: StretchMotion(), children: [ - SlideAction(color: Colors.green, icon: Icons.share), - SlideAction(color: Colors.amber, icon: Icons.delete), + SlideAction( + color: Colors.green, + icon: SizedBox( + child: Icon(Icons.share), + )), + SlideAction( + color: Colors.amber, + icon: SizedBox( + child: Icon(Icons.delete), + )), ], ), endActionPane: const ActionPane( motion: StretchMotion(), children: [ - SlideAction(color: Colors.red, icon: Icons.delete_forever), - SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 3), + SlideAction( + color: Colors.red, + icon: SizedBox( + child: Icon(Icons.delete), + )), + SlideAction( + color: Colors.blue, + icon: SizedBox( + child: Icon(Icons.alarm), + ), + flex: 3), ], ), child: const Tile(color: Colors.pink, text: 'hello 2'), @@ -102,15 +134,32 @@ class _MyHomePageState extends State { startActionPane: const ActionPane( motion: ScrollMotion(), children: [ - SlideAction(color: Colors.green, icon: Icons.share), - SlideAction(color: Colors.amber, icon: Icons.delete), + SlideAction( + color: Colors.green, + icon: SizedBox( + child: Icon(Icons.share), + )), + SlideAction( + color: Colors.amber, + icon: SizedBox( + child: Icon(Icons.delete), + )), ], ), endActionPane: const ActionPane( motion: ScrollMotion(), children: [ - SlideAction(color: Colors.red, icon: Icons.delete_forever), - SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2), + SlideAction( + color: Colors.red, + icon: SizedBox( + child: Icon(Icons.delete), + )), + SlideAction( + color: Colors.blue, + icon: SizedBox( + child: Icon(Icons.alarm), + ), + flex: 2), ], ), child: const Tile(color: Colors.yellow, text: 'hello 3'), @@ -160,17 +209,32 @@ class _MyHomePageState extends State { }, ), children: const [ - SlideAction(color: Colors.green, icon: Icons.share), - SlideAction(color: Colors.amber, icon: Icons.delete), + SlideAction( + color: Colors.green, + icon: SizedBox( + child: Icon(Icons.share), + )), + SlideAction( + color: Colors.amber, + icon: SizedBox( + child: Icon(Icons.delete), + )), ], ), endActionPane: const ActionPane( motion: DrawerMotion(), children: [ SlideAction( - color: Colors.red, icon: Icons.delete_forever), + color: Colors.red, + icon: SizedBox( + child: Icon(Icons.delete), + )), SlideAction( - color: Colors.blue, icon: Icons.alarm, flex: 2), + color: Colors.blue, + icon: SizedBox( + child: Icon(Icons.alarm), + ), + flex: 2), ], ), child: const Tile(color: Colors.lime, text: 'hello 4'), @@ -192,7 +256,7 @@ class SlideAction extends StatelessWidget { }) : super(key: key); final Color color; - final IconData icon; + final Widget icon; final int flex; @override diff --git a/example/pubspec.lock b/example/pubspec.lock index 38587e62..f02f954a 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.8.2" + version: "2.9.0" boolean_selector: dependency: transitive description: @@ -21,21 +21,14 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" + version: "1.2.1" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: @@ -56,7 +49,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -80,28 +73,28 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.11" + version: "0.12.12" material_color_utilities: dependency: transitive description: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.4" + version: "0.1.5" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" sky_engine: dependency: transitive description: flutter @@ -113,7 +106,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.2" + version: "1.9.0" stack_trace: dependency: transitive description: @@ -134,21 +127,21 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.9" + version: "0.4.12" vector_math: dependency: transitive description: diff --git a/lib/src/actions.dart b/lib/src/actions.dart index 1dbc8e4d..719b4861 100644 --- a/lib/src/actions.dart +++ b/lib/src/actions.dart @@ -97,10 +97,10 @@ class CustomSlidableAction extends StatelessWidget { child: OutlinedButton( onPressed: () => _handleTap(context), style: OutlinedButton.styleFrom( + foregroundColor: effectiveForegroundColor, padding: padding, backgroundColor: backgroundColor, - primary: effectiveForegroundColor, - onSurface: effectiveForegroundColor, + disabledForegroundColor: effectiveForegroundColor.withOpacity(0.38), shape: RoundedRectangleBorder( borderRadius: borderRadius, ), @@ -162,7 +162,7 @@ class SlidableAction extends StatelessWidget { final SlidableActionCallback? onPressed; /// An icon to display above the [label]. - final IconData? icon; + final Widget? icon; /// The space between [icon] and [label] if both set. /// @@ -184,7 +184,7 @@ class SlidableAction extends StatelessWidget { if (icon != null) { children.add( - Icon(icon), + Container(), ); } diff --git a/pubspec.lock b/pubspec.lock index 8d638223..cb072ef3 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -28,7 +28,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.8.2" + version: "2.9.0" boolean_selector: dependency: transitive description: @@ -42,7 +42,7 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" charcode: dependency: transitive description: @@ -56,7 +56,7 @@ packages: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: "direct dev" description: @@ -91,7 +91,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.1" file: dependency: transitive description: @@ -164,21 +164,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.11" + version: "0.12.12" material_color_utilities: dependency: transitive description: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.4" + version: "0.1.5" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0" mime: dependency: transitive description: @@ -213,7 +213,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" pool: dependency: transitive description: @@ -281,7 +281,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.2" + version: "1.9.0" stack_trace: dependency: transitive description: @@ -302,35 +302,35 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" test: dependency: transitive description: name: test url: "https://pub.dartlang.org" source: hosted - version: "1.21.1" + version: "1.21.4" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.9" + version: "0.4.12" test_core: dependency: transitive description: name: test_core url: "https://pub.dartlang.org" source: hosted - version: "0.4.13" + version: "0.4.16" typed_data: dependency: transitive description: diff --git a/test/actions_test.dart b/test/actions_test.dart index 745a17a3..2b2e4b01 100644 --- a/test/actions_test.dart +++ b/test/actions_test.dart @@ -80,7 +80,7 @@ void main() { children: [ SlidableAction( onPressed: (_) => logs.add('pressed'), - icon: Icons.ac_unit, + icon: Container(), ) ], ), @@ -99,7 +99,7 @@ void main() { children: [ SlidableAction( onPressed: (_) => logs.add('pressed'), - icon: Icons.ac_unit, + icon: Container(), label: 'my_label', ) ], diff --git a/test/dismissible_pane_test.dart b/test/dismissible_pane_test.dart index c63f7a20..96b2d889 100644 --- a/test/dismissible_pane_test.dart +++ b/test/dismissible_pane_test.dart @@ -1,4 +1,3 @@ -import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter_slidable/src/action_pane_motions.dart'; import 'package:flutter_slidable/src/actions.dart'; @@ -34,8 +33,16 @@ void main() { ), motion: const BehindMotion(), children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.share), + )), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.share), + )), ], ), child: const SizedBox.expand(), @@ -77,8 +84,16 @@ void main() { ), motion: const BehindMotion(), children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.share), + )), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.delete), + )), ], ), child: const SizedBox.expand(), @@ -124,8 +139,16 @@ void main() { ), motion: const BehindMotion(), children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.share), + )), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.delete), + )), ], ), child: const SizedBox.expand(), @@ -174,8 +197,16 @@ void main() { ), motion: const BehindMotion(), children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.share), + )), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.delete), + )), ], ), child: const SizedBox.expand(), @@ -226,8 +257,16 @@ void main() { ), motion: const BehindMotion(), children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.share), + )), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.delete), + )), ], ), child: const SizedBox.expand(), @@ -282,8 +321,16 @@ void main() { ), motion: const BehindMotion(), children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.share), + )), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.delete), + )), ], ), child: const SizedBox.expand(), @@ -340,8 +387,16 @@ void main() { ), motion: const BehindMotion(), children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.share), + )), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.delete), + )), ], ), child: Builder( diff --git a/test/slidable_test.dart b/test/slidable_test.dart index f2a5a477..227bdaf6 100644 --- a/test/slidable_test.dart +++ b/test/slidable_test.dart @@ -21,16 +21,32 @@ void main() { key: startActionPaneKey, motion: const BehindMotion(), children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.share), + )), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.delete), + )), ], ), endActionPane: ActionPane( key: endActionPaneKey, motion: const ScrollMotion(), children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.share), + )), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.delete), + )), ], ), child: Builder(builder: (context) { @@ -68,16 +84,32 @@ void main() { key: startActionPaneKey, motion: const BehindMotion(), children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.share), + )), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.delete), + )), ], ), endActionPane: ActionPane( key: endActionPaneKey, motion: const ScrollMotion(), children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.share), + )), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.delete), + )), ], ), child: Builder(builder: (context) { @@ -116,16 +148,32 @@ void main() { key: startActionPaneKey, motion: const BehindMotion(), children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.share), + )), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.delete), + )), ], ), endActionPane: ActionPane( key: endActionPaneKey, motion: const ScrollMotion(), children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.share), + )), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.delete), + )), ], ), child: Builder(builder: (context) { @@ -164,16 +212,32 @@ void main() { key: startActionPaneKey, motion: const BehindMotion(), children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.share), + )), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.delete), + )), ], ), endActionPane: ActionPane( key: endActionPaneKey, motion: const ScrollMotion(), children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.share), + )), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.delete), + )), ], ), child: Builder(builder: (context) { @@ -213,8 +277,16 @@ void main() { key: endActionPaneKey, motion: const ScrollMotion(), children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.share), + )), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.delete), + )), ], ), child: Builder( @@ -253,8 +325,16 @@ void main() { key: startActionPaneKey, motion: const ScrollMotion(), children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.share), + )), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.delete), + )), ], ), child: Builder( @@ -288,8 +368,16 @@ void main() { key: actionPaneKey, motion: const BehindMotion(), children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.share), + )), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.delete), + )), ], ); @@ -326,8 +414,16 @@ void main() { key: actionPaneKey, motion: const BehindMotion(), children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.share), + )), + SlidableAction( + onPressed: (_) {}, + icon: const SizedBox( + child: Icon(Icons.delete), + )), ], ); From a375096add845e787e61f7a2f303180777257e12 Mon Sep 17 00:00:00 2001 From: Fahad Saleem Date: Fri, 13 Jan 2023 14:38:39 +0500 Subject: [PATCH 2/2] fix icon widget issue --- lib/src/actions.dart | 10 +++------- test/actions_test.dart | 2 ++ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/src/actions.dart b/lib/src/actions.dart index 719b4861..5be20233 100644 --- a/lib/src/actions.dart +++ b/lib/src/actions.dart @@ -137,7 +137,7 @@ class SlidableAction extends StatelessWidget { this.foregroundColor, this.autoClose = _kAutoClose, required this.onPressed, - this.icon, + required this.icon, this.spacing = 4, this.label, this.borderRadius = BorderRadius.zero, @@ -162,7 +162,7 @@ class SlidableAction extends StatelessWidget { final SlidableActionCallback? onPressed; /// An icon to display above the [label]. - final Widget? icon; + final Widget icon; /// The space between [icon] and [label] if both set. /// @@ -182,11 +182,7 @@ class SlidableAction extends StatelessWidget { Widget build(BuildContext context) { final children = []; - if (icon != null) { - children.add( - Container(), - ); - } + children.add(icon); if (label != null) { if (children.isNotEmpty) { diff --git a/test/actions_test.dart b/test/actions_test.dart index 2b2e4b01..f439b229 100644 --- a/test/actions_test.dart +++ b/test/actions_test.dart @@ -37,6 +37,7 @@ void main() { child: Row( children: [ SlidableAction( + icon: const Icon(Icons.save), onPressed: (_) => logs.add('pressed'), label: 'label', ) @@ -60,6 +61,7 @@ void main() { child: Row( children: [ SlidableAction( + icon: const Icon(Icons.save), onPressed: (_) => logs.add('pressed'), label: 'my_label', )