mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
add tabbar
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:qinglong_app/utils/qinglong_theme.dart';
|
||||
|
||||
var themeProvider = ChangeNotifierProvider((ref) => ThemeViewModel());
|
||||
const Color _primaryColor = Color(0xFF299343);
|
||||
@@ -48,7 +49,19 @@ ThemeData lightTheme = ThemeData.light().copyWith(
|
||||
progressIndicatorTheme: const ProgressIndicatorThemeData(
|
||||
color: _primaryColor,
|
||||
),
|
||||
|
||||
tabBarTheme: const TabBarTheme(
|
||||
labelStyle: TextStyle(
|
||||
fontSize: 16,
|
||||
),
|
||||
unselectedLabelStyle: TextStyle(
|
||||
fontSize: 16,
|
||||
),
|
||||
labelColor: _primaryColor,
|
||||
unselectedLabelColor: Color(0xff999999),
|
||||
indicator: UnderlineTabIndicator(
|
||||
borderSide: BorderSide(color: _primaryColor),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
abstract class ThemeColors {
|
||||
@@ -57,6 +70,8 @@ abstract class ThemeColors {
|
||||
Color searchBarBg();
|
||||
|
||||
Color pinColor();
|
||||
|
||||
Map<String, TextStyle> codeEditorTheme();
|
||||
}
|
||||
|
||||
class LightartThemeColors extends ThemeColors {
|
||||
@@ -74,6 +89,11 @@ class LightartThemeColors extends ThemeColors {
|
||||
Color pinColor() {
|
||||
return const Color(0xffF7F7F7);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, TextStyle> codeEditorTheme() {
|
||||
return qinglongLightTheme;
|
||||
}
|
||||
}
|
||||
|
||||
class DartThemeColors extends ThemeColors {
|
||||
@@ -91,4 +111,9 @@ class DartThemeColors extends ThemeColors {
|
||||
Color pinColor() {
|
||||
return Colors.black12;
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, TextStyle> codeEditorTheme() {
|
||||
return qinglongDarkTheme;
|
||||
}
|
||||
}
|
||||
|
||||
71
lib/base/ui/abs_underline_tabindicator.dart
Normal file
71
lib/base/ui/abs_underline_tabindicator.dart
Normal file
@@ -0,0 +1,71 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
|
||||
///tabbar样式下方横条固定宽度
|
||||
class AbsUnderlineTabIndicator extends Decoration {
|
||||
const AbsUnderlineTabIndicator({
|
||||
this.wantWidth,
|
||||
this.borderSide = const BorderSide(width: 2.0, color: Colors.white),
|
||||
this.insets = EdgeInsets.zero,
|
||||
}) : assert(borderSide != null),
|
||||
assert(insets != null);
|
||||
|
||||
final BorderSide? borderSide;
|
||||
final double? wantWidth;
|
||||
|
||||
final EdgeInsetsGeometry? insets;
|
||||
|
||||
@override
|
||||
Decoration? lerpFrom(Decoration? a, double t) {
|
||||
if (a is UnderlineTabIndicator) {
|
||||
return UnderlineTabIndicator(
|
||||
borderSide: BorderSide.lerp(a.borderSide, borderSide!, t),
|
||||
insets: EdgeInsetsGeometry.lerp(a.insets, insets, t)!,
|
||||
);
|
||||
}
|
||||
return super.lerpFrom(a, t);
|
||||
}
|
||||
|
||||
@override
|
||||
Decoration? lerpTo(Decoration? b, double t) {
|
||||
if (b is UnderlineTabIndicator) {
|
||||
return UnderlineTabIndicator(
|
||||
borderSide: BorderSide.lerp(borderSide!, b.borderSide, t),
|
||||
insets: EdgeInsetsGeometry.lerp(insets, b.insets, t)!,
|
||||
);
|
||||
}
|
||||
return super.lerpTo(b, t);
|
||||
}
|
||||
|
||||
@override
|
||||
_UnderlinePainter createBoxPainter([VoidCallback? onChanged]) {
|
||||
return _UnderlinePainter(this, onChanged);
|
||||
}
|
||||
}
|
||||
|
||||
class _UnderlinePainter extends BoxPainter {
|
||||
_UnderlinePainter(this.decoration, VoidCallback? onChanged) : super(onChanged);
|
||||
|
||||
final AbsUnderlineTabIndicator decoration;
|
||||
|
||||
BorderSide? get borderSide => decoration.borderSide;
|
||||
|
||||
EdgeInsetsGeometry? get insets => decoration.insets;
|
||||
|
||||
Rect _indicatorRectFor(Rect rect, TextDirection textDirection) {
|
||||
final Rect indicator = insets!.resolve(textDirection).deflateRect(rect);
|
||||
//取中间坐标
|
||||
double cw = (indicator.left + indicator.right) / 2;
|
||||
return Rect.fromLTWH(cw - decoration.wantWidth! / 2, indicator.bottom - borderSide!.width, decoration.wantWidth!, borderSide!.width);
|
||||
}
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
|
||||
assert(configuration.size != null);
|
||||
final Rect rect = offset & configuration.size!;
|
||||
final TextDirection textDirection = configuration.textDirection!;
|
||||
final Rect indicator = _indicatorRectFor(rect, textDirection).deflate(borderSide!.width / 2.0);
|
||||
final Paint paint = borderSide!.toPaint()..strokeCap = StrokeCap.round;
|
||||
canvas.drawLine(indicator.bottomLeft, indicator.bottomRight, paint);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user