Skip to content

Commit

Permalink
Bump up version to 0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Dat committed Apr 16, 2024
1 parent 0331006 commit 9097997
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.1
* Added label color, style for each Tab
* Updated example project

## 0.1.0
* Migrated to null safety.

Expand Down
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ A colorful TabBar for Flutter where each tab has a color (inspired by SmartNews
## Getting Started

Add this to your package's pubspec.yaml file:
````
```yaml
dependencies:
flutter_colorful_tab: "^0.1.0"
````
flutter_colorful_tab: {current_version}
```
Import the library in your file:
````
```dart
import 'package:flutter_colorful_tab/flutter_colorful_tab.dart';
````
```

Use the flutter_colorful_tab like this:
````
```dart
ColorfulTabBar(
tabs: [
TabItem(color: Colors.red, title: Text('Home')),
Expand All @@ -28,4 +28,15 @@ ColorfulTabBar(
],
controller: _tabController,
)
````
// all available parameters of TabItem
TabItem(
color: Colors.orange,
unselectedColor: Colors.orange.shade600,
title: const Text('Search'),
labelColor: Colors.black,
unselectedLabelColor: Colors.yellow,
labelStyle: const TextStyle(fontWeight: FontWeight.bold),
unselectedLabelStyle: const TextStyle(fontWeight: FontWeight.normal),
),
```
17 changes: 15 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,24 @@ class _MyHomePageState extends State<MyHomePage>
selectedHeight: 48,
unselectedHeight: 40,
tabs: [
TabItem(color: Colors.red, title: const Text('Tab 1 - Home')),
TabItem(
color: Colors.red,
title: const Text('Tab 1 - Home'),
labelColor: Colors.black,
unselectedLabelColor: Colors.yellow.shade600,
),
TabItem(
color: Colors.green, title: const Text('Tab 2 - Favorite')),
TabItem(
color: Colors.orange, title: const Text('Tab 3 - Search')),
color: Colors.orange,
title: const Text('Tab 3 - Search'),
labelColor: Colors.black,
unselectedLabelColor: Colors.yellow.shade600,
labelStyle: const TextStyle(
fontSize: 20, fontWeight: FontWeight.bold),
unselectedLabelStyle: const TextStyle(
fontSize: 20, fontWeight: FontWeight.normal),
),
TabItem(
color: Colors.blue, title: const Text('Tab 4 - Settings')),
TabItem(
Expand Down
50 changes: 41 additions & 9 deletions lib/flutter_colorful_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ library flutter_colorful_tab;

import 'dart:math';
import 'dart:ui';

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

/// Tab info that hold the title widget and tab color.
class TabItem {
TabItem({required this.color, required this.title, Color? unselectedColor})
: this.unSelectedColor = unselectedColor ?? color;
TabItem({
required this.color,
required this.title,
Color? unselectedColor,
this.labelColor,
this.unselectedLabelColor,
this.labelStyle,
this.unselectedLabelStyle,
}) : this.unSelectedColor = unselectedColor ?? color;

/// tab color, must be non-null
final Color color;
Expand All @@ -18,6 +26,26 @@ class TabItem {

/// tab color when unselected
final Color unSelectedColor;

/// The color of the selected tab label.
///
/// If null, defaults to the value of [ColorfulTabBar.labelColor].
final Color? labelColor;

/// The color of unselected tab label.
///
/// If null, defaults to the value of [ColorfulTabBar.unselectedLabelColor].
final Color? unselectedLabelColor;

/// The text style of the selected tab labels.
///
/// If null, defaults to the value of [ColorfulTabBar.labelStyle].
final TextStyle? labelStyle;

/// The text style of the unselected tab labels.
///
/// If null, defaults to the value of [ColorfulTabBar.unselectedLabelStyle].
final TextStyle? unselectedLabelStyle;
}

/// How the tabs should be placed along the main axis in a tabbar.
Expand Down Expand Up @@ -548,24 +576,28 @@ class _TabItemWidget extends AnimatedWidget {

// To enable TextStyle.lerp(style1, style2, value), both styles must have
// the same value of inherit. Force that to be inherit=true here.
final TextStyle defaultStyle = (tabBar.labelStyle ??
final TextStyle defaultStyle = (tab.labelStyle ??
tabBar.labelStyle ??
tabBarTheme.labelStyle ??
themeData.primaryTextTheme.bodyText1!)
themeData.primaryTextTheme.bodyLarge!)
.copyWith(inherit: true);
final TextStyle defaultUnselectedStyle = (tabBar.unselectedLabelStyle ??
final TextStyle defaultUnselectedStyle = (tab.unselectedLabelStyle ??
tabBar.unselectedLabelStyle ??
tabBarTheme.unselectedLabelStyle ??
tabBar.labelStyle ??
themeData.primaryTextTheme.bodyText1!)
themeData.primaryTextTheme.bodyLarge!)
.copyWith(inherit: true);
final TextStyle textStyle = selected
? TextStyle.lerp(defaultStyle, defaultUnselectedStyle, animation.value)!
: TextStyle.lerp(
defaultUnselectedStyle, defaultStyle, animation.value)!;

final Color selectedColor = tabBar.labelColor ??
final Color selectedColor = tab.labelColor ??
tabBar.labelColor ??
tabBarTheme.labelColor ??
themeData.primaryTextTheme.bodyText1!.color!;
final Color unselectedColor = tabBar.unselectedLabelColor ??
themeData.primaryTextTheme.bodyLarge!.color!;
final Color unselectedColor = tab.unselectedLabelColor ??
tabBar.unselectedLabelColor ??
tabBarTheme.unselectedLabelColor ??
selectedColor.withAlpha(0xB2); // 70% alpha

Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: flutter_colorful_tab
description: A colorful TabBar for Flutter where each tab has a color (inspired by SmartNews app).
version: 0.1.0
version: 0.1.1
homepage: https://github.com/datdescartes/flutter_colorful_tab

environment:
sdk: ">=2.12.0 <3.0.0"
sdk: ">=2.12.0 <4.0.0"
flutter: ">=1.17.0"

dependencies:
Expand Down

0 comments on commit 9097997

Please sign in to comment.