我尝试使用以前的帖子所建议的BoxDecoration,但它并不能完全按照我的意愿显示。
TabBar(
labelColor: Theme.of(context).primaryColor,
indicator: BoxDecoration(
gradient: LinearGradient(
colors: const [Color(0xFF10C7E0), Color(0xFF00D5C3)],
),
),
tabs: ...,
),
有人指出,该帖子与10个月前发布的how-to-give-a-gradient-line-in-tab-bar-indicator重复。但是那里显示的方法不再起作用。是的,我尝试过。
答案 0 :(得分:3)
此选项有什么问题? (基于链接中的代码)
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
title: Text('All', style: TextStyle(color: const Color(0xff596173))),
backgroundColor: Colors.white,
centerTitle: true,
bottom: TabBar(
labelColor: const Color(0xff525c6e),
unselectedLabelColor: const Color(0xffacb3bf),
indicatorPadding: EdgeInsets.all(0.0),
indicatorWeight: 4.0,
labelPadding: EdgeInsets.only(left: 0.0, right: 0.0),
indicator: ShapeDecoration(
shape: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.transparent, width: 0, style: BorderStyle.solid)),
gradient: LinearGradient(colors: [Color(0xff0081ff), Color(0xff01ff80)])),
tabs: <Widget>[
Container(
height: 40,
alignment: Alignment.center,
color: Colors.white,
child: Text("Visual"),
),
Container(
height: 40,
alignment: Alignment.center,
color: Colors.white,
child: Text("Tabular"),
),
],
),
),
body: Container(color: Colors.grey[200]),
),
),
);
}
}
答案 1 :(得分:0)
尝试将其替换为以下内容:
指标:容器( 对齐方式:Alignment.bottomCenter, 子代:集装箱( 高度:8.0 装饰:BoxDecoration(...) )
从我的iPhone发布