Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat style #39

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 45 additions & 20 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:tabbed_view/tabbed_view.dart';

Expand All @@ -8,8 +10,7 @@ void main() {
class TabbedViewExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false, home: TabbedViewExamplePage());
return MaterialApp(debugShowCheckedModeBanner: false, home: TabbedViewExamplePage());
}
}

Expand All @@ -26,32 +27,56 @@ class _TabbedViewExamplePageState extends State<TabbedViewExamplePage> {
super.initState();
List<TabData> tabs = [];

tabs.add(TabData(text: 'Tab 1', leading: (context, status) => Icon(Icons.star, size: 16), content: Padding(child: Text('Hello'), padding: EdgeInsets.all(8))));
tabs.add(TabData(text: 'Tab 2', content: Padding(child: Text('Hello again'), padding: EdgeInsets.all(8))));
tabs.add(TabData(
text: 'Tab 1',
leading: (context, status) => Icon(Icons.star, size: 16),
content: Padding(child: Text('Hello'), padding: EdgeInsets.all(8))));
tabs.add(TabData(
text: 'Tab 2',
content:
Padding(child: Text('Hello again'), padding: EdgeInsets.all(8))));
tabs.add(TabData(
closable: false,
text: 'TextField',
content: Padding(
child: TextField(
decoration: InputDecoration(
isDense: true, border: OutlineInputBorder())),
padding: EdgeInsets.all(8)),
keepAlive: true));
closable: false, text: 'TextField', content: Padding(child: TextField(decoration: InputDecoration(isDense: true, border: OutlineInputBorder())), padding: EdgeInsets.all(8)), keepAlive: true));

_controller = TabbedViewController(tabs);
}

@override
Widget build(BuildContext context) {
TabbedView tabbedView = TabbedView(controller: _controller);
Widget w =
TabbedViewTheme(child: tabbedView, data: TabbedViewThemeData.mobile());
TabbedViewThemeData themeData = TabbedViewThemeData.classic();
themeData.tabsArea
..addButton = TabButton(
icon: IconProvider.data(Icons.add),
onPressed: () {
_controller.addTab(TabData(
text: DateTime.now().toString(),
content: const Center(
child: Text('New Tab'),
)));
})
..dropColor = Colors.red
..dropOverPainter = _CustomDropOverPainter();
themeData.menu.maxWidth = 100;
themeData.tab
..maxWidth = 100
..minWidth = 50
..decoration = BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(4),
border: Border.all(color: Colors.orange, width: 5),
);
Widget w = TabbedViewTheme(child: tabbedView, data: themeData);
return Scaffold(body: Container(child: w, padding: EdgeInsets.all(32)));
}
}

class _CustomDropOverPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
Paint paint = Paint()
..color = Colors.red
..style = PaintingStyle.fill;
canvas.drawCircle(Offset(0,size.height/2), 4, paint);
canvas.drawRRect(RRect.fromLTRBXY(0, 4, 4, size.height, 2, 2), paint);
}

@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return true;
}
}
2 changes: 1 addition & 1 deletion example/macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
331C80D4294CF70F00263BE5 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
27 changes: 7 additions & 20 deletions lib/src/internal/tabs_area/drop_tab_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import 'package:tabbed_view/src/theme/theme_widget.dart';

@internal
class DropTabWidget extends StatefulWidget {
const DropTabWidget(
{super.key,
required this.provider,
required this.newIndex,
required this.child});
const DropTabWidget({super.key, required this.provider, required this.newIndex, required this.child});

final TabbedViewProvider provider;
final Widget child;
Expand Down Expand Up @@ -54,10 +50,7 @@ class DropTabWidgetState extends State<DropTabWidget> {
) {
if (_over) {
TabbedViewThemeData theme = TabbedViewTheme.of(context);
return CustomPaint(
foregroundPainter:
_CustomPainter(dropColor: theme.tabsArea.dropColor),
child: widget.child);
return CustomPaint(foregroundPainter: theme.tabsArea.dropOverPainter ?? _CustomPainter(dropColor: theme.tabsArea.dropColor), child: widget.child);
}
return widget.child;
},
Expand All @@ -72,18 +65,15 @@ class DropTabWidgetState extends State<DropTabWidget> {
if (widget.provider.canDrop == null) {
_canDrop = true;
} else if (data != null) {
_canDrop =
widget.provider.canDrop!(data, widget.provider.controller);
_canDrop = widget.provider.canDrop!(data, widget.provider.controller);
} else {
_canDrop = false;
}
return _canDrop;
},
onAccept: (DraggableData data) {
if (widget.provider.onBeforeDropAccept != null) {
if (widget.provider.onBeforeDropAccept!(
data, widget.provider.controller, widget.newIndex) ==
false) {
if (widget.provider.onBeforeDropAccept!(data, widget.provider.controller, widget.newIndex) == false) {
setState(() {
_over = false;
_canDrop = false;
Expand All @@ -92,12 +82,10 @@ class DropTabWidgetState extends State<DropTabWidget> {
}
}
if (widget.provider.controller == data.controller) {
widget.provider.controller
.reorderTab(data.tabData.index, widget.newIndex);
widget.provider.controller.reorderTab(data.tabData.index, widget.newIndex);
} else {
data.controller.removeTab(data.tabData.index);
widget.provider.controller
.insertTab(widget.newIndex, data.tabData);
widget.provider.controller.insertTab(widget.newIndex, data.tabData);
}
},
));
Expand All @@ -114,8 +102,7 @@ class _CustomPainter extends CustomPainter {
Paint paint = Paint()
..color = dropColor
..style = PaintingStyle.fill;
canvas.drawRect(
Rect.fromLTWH(0, 0, DropTabWidget.dropWidth, size.height), paint);
canvas.drawRect(Rect.fromLTWH(0, 0, DropTabWidget.dropWidth, size.height), paint);
}

@override
Expand Down
40 changes: 25 additions & 15 deletions lib/src/internal/tabs_area/tabs_area_corner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,45 @@ import 'package:tabbed_view/src/internal/tabbed_view_provider.dart';
import 'package:tabbed_view/src/internal/tabs_area/drop_tab_widget.dart';
import 'package:tabbed_view/src/internal/tabs_area/hidden_tabs.dart';
import 'package:tabbed_view/src/internal/tabs_area/tabs_area_buttons_widget.dart';
import 'package:tabbed_view/tabbed_view.dart';

@internal
class TabsAreaCorner extends StatelessWidget {
final TabbedViewProvider provider;
final HiddenTabs hiddenTabs;

const TabsAreaCorner(
{super.key, required this.provider, required this.hiddenTabs});
const TabsAreaCorner({super.key, required this.provider, required this.hiddenTabs});

@override
Widget build(BuildContext context) {
return ListenableBuilder(listenable: hiddenTabs, builder: _builder);
}

Widget _builder(BuildContext context, Widget? child) {
Widget corner = Container(
padding: EdgeInsets.only(left: DropTabWidget.dropWidth),
child: Row(
children: [
TabsAreaButtonsWidget(provider: provider, hiddenTabs: hiddenTabs)
],
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end));
if (provider.controller.reorderEnable) {
TabbedViewThemeData theme = TabbedViewTheme.of(context);
TabsAreaThemeData tabsAreaTheme = theme.tabsArea;
TabThemeData tabTheme = theme.tab;
Widget areaButtons = Container(
margin: tabTheme.margin,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: [TabsAreaButtonsWidget(provider: provider, hiddenTabs: hiddenTabs)],
),
);
if (tabsAreaTheme.addButton != null) {
return areaButtons;
}
if(provider.controller.reorderEnable) {
return DropTabWidget(
provider: provider,
newIndex: provider.controller.length,
child: corner);
provider: provider,
newIndex: provider.controller.length,
child: Container(
padding: const EdgeInsets.only(left: DropTabWidget.dropWidth),
child: areaButtons,
),
);
}
return corner;
return areaButtons;
}
}
Loading