EMR*_*ADE 3 flutter flutter-layout
我正在尝试创建一个具有渐变下划线的 TabBar,如下图所示。

我尝试按照之前的帖子的建议使用 BoxDecoration,但它并没有完全按照我的意愿显示。
TabBar(
labelColor: Theme.of(context).primaryColor,
indicator: BoxDecoration(
gradient: LinearGradient(
colors: const [Color(0xFF10C7E0), Color(0xFF00D5C3)],
),
),
tabs: ...,
),
Run Code Online (Sandbox Code Playgroud)
有人指出,这篇文章是10 个月前发布的how-to-give-a-gradient-line-in-tab-bar-indicator的重复。但是那里说明的方法不再有效。是的,我试过了。
小智 8
这个选项有什么问题?(基于链接中的代码)
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]),
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3561 次 |
| 最近记录: |