-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Highlighting the tab's drop position.
- Loading branch information
1 parent
3ca916f
commit 5ab4ec8
Showing
3 changed files
with
90 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 1.18.0 | ||
|
||
* Highlighting the tab's drop position. | ||
|
||
## 1.17.0 | ||
|
||
* Tab reordering | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:meta/meta.dart'; | ||
import 'package:tabbed_view/src/internal/tabbed_view_provider.dart'; | ||
import 'package:tabbed_view/src/tab_data.dart'; | ||
|
||
@internal | ||
class DropTabWidget extends StatefulWidget { | ||
const DropTabWidget( | ||
{super.key, | ||
required this.provider, | ||
required this.newIndex, | ||
required this.child}); | ||
|
||
final TabbedViewProvider provider; | ||
final Widget child; | ||
final int newIndex; | ||
|
||
@override | ||
State<StatefulWidget> createState() => DropTabWidgetState(); | ||
} | ||
|
||
class DropTabWidgetState extends State<DropTabWidget> { | ||
bool _over = false; | ||
|
||
@override | ||
void didUpdateWidget(covariant DropTabWidget oldWidget) { | ||
super.didUpdateWidget(oldWidget); | ||
if (widget.provider.draggingTabIndex == null) { | ||
_over = false; | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return DragTarget<TabData>( | ||
builder: ( | ||
BuildContext context, | ||
List<dynamic> accepted, | ||
List<dynamic> rejected, | ||
) { | ||
if (_over) { | ||
return CustomPaint( | ||
foregroundPainter: _CustomPainter(), child: widget.child); | ||
} | ||
return widget.child; | ||
}, | ||
onMove: (details) { | ||
if (_over == false) { | ||
setState(() { | ||
_over = true; | ||
}); | ||
} | ||
}, | ||
onLeave: (data) { | ||
setState(() { | ||
_over = false; | ||
}); | ||
}, | ||
onAccept: (TabData tabData) { | ||
widget.provider.controller.reorderTab(tabData.index, widget.newIndex); | ||
}, | ||
); | ||
} | ||
} | ||
|
||
class _CustomPainter extends CustomPainter { | ||
@override | ||
void paint(Canvas canvas, Size size) { | ||
Paint paint = Paint() | ||
..color = Colors.black | ||
..style = PaintingStyle.fill; | ||
canvas.drawRect(Rect.fromLTWH(0, 0, 3, size.height), paint); | ||
} | ||
|
||
@override | ||
bool shouldRepaint(covariant CustomPainter oldDelegate) { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters