- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想要的:
我想创建一个类似 TabBar();
的按钮,它就像一个带下划线的 ToggleButton()
。
好吧,这个按钮的功能应该类似于ToggleButton(),
refer here. for toggleButton class.
到目前为止我尝试了什么:
ToggleButtons(
borderRadius: BorderRadius.zero,
children: [
RichText(
text: TextSpan(
text: "Today",
style: TextStyle(
color: Colors.black, fontSize: 15),
children: [
TextSpan(
text:
" ${offline.length.toString()} Slots",
style: TextStyle(color: Colors.green))
],
),
),
RichText(
text: TextSpan(
text: "Today",
style: TextStyle(
color: Colors.black, fontSize: 15),
children: [
TextSpan(
text:
" ${offline.length.toString()} Slots",
style: TextStyle(color: Colors.green))
],
),
),
],
isSelected: isSelected,
onPressed: (int index) {
setState(
() {
for (int buttonIndex = 0;
buttonIndex < isSelected.length;
buttonIndex++) {
if (buttonIndex == index) {
isSelected[buttonIndex] = true;
} else {
isSelected[buttonIndex] = false;
}
}
},
);
},
),
以上代码的输出:
最佳答案
我只创建了一个 Custom Toggle Button
,它具有所有功能,例如 onTap
,调用函数
。我希望这能解决您的问题,请看下面的示例
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
accentColor: Colors.blue,
),
home: CustomToggleButton(),
);
}
}
class CustomToggleButton extends StatefulWidget {
@override
_CustomToggleButtonState createState() => _CustomToggleButtonState();
}
const double width = 300.0;
const double height = 60.0;
const double todayAlign = -1;
const double signInAlign = 1;
const Color selectedColor = Colors.black;
const Color normalColor = Colors.black38;
class _CustomToggleButtonState extends State<CustomToggleButton> {
double xAlign;
Color todayColor;
Color tomorrowColor;
bool selectedValue;
@override
void initState() {
super.initState();
xAlign = todayAlign;
todayColor = selectedColor;
tomorrowColor = normalColor;
selectedValue = true;
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
color: Colors.white,
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Column(
children: [
Container(
height: 10,
),
Container(
width: width,
height: 100,
decoration: const BoxDecoration(
// color: Colors.red,
borderRadius: BorderRadius.all(
Radius.circular(00.0),
),
),
child: Stack(
children: [
AnimatedAlign(
alignment: Alignment(xAlign, 0),
duration: Duration(milliseconds: 300),
child: Container(
color: Colors.red,
width: width * 0.5,
height: 70,
child: Container(
decoration: const BoxDecoration(
// color: Colors.pink,
gradient: LinearGradient(
colors: [
Colors.white,
Colors.white,
Colors.white,
Colors.white,
Colors.pink
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
// stops: [0.0, 1.0],
// tileMode: TileMode.clamp
),
),
),
),
),
GestureDetector(
onTap: () {
setState(() {
xAlign = todayAlign;
todayColor = selectedColor;
tomorrowColor = normalColor;
selectedValue = true;
});
},
child: Align(
alignment: Alignment(-1, 0),
child: Container(
width: width * 0.5,
color: Colors.transparent,
alignment: Alignment.center,
child: RichText(
text: TextSpan(
text: "Today",
style: TextStyle(color: todayColor, fontSize: 15),
children: [
TextSpan(
text: " 2 Slots",
style: TextStyle(color: Colors.green))
],
),
),
),
),
),
GestureDetector(
onTap: () {
setState(() {
xAlign = signInAlign;
tomorrowColor = selectedColor;
selectedValue = false;
todayColor = normalColor;
});
},
child: Align(
alignment: Alignment(1, 0),
child: Container(
width: width * 0.5,
color: Colors.transparent,
alignment: Alignment.center,
child: RichText(
text: TextSpan(
text: "Tomorrow",
style:
TextStyle(color: tomorrowColor, fontSize: 15),
children: [
TextSpan(
text: " 3 Slots",
style: TextStyle(color: Colors.green))
],
),
),
),
),
),
],
),
),
Container(
height: 20,
),
Expanded(
child: Container(
child: selectedValue ? Text("Today Data") : Text(" Tomorrow Data"),
),
)
],
),
));
}
}
关于flutter - 如何在 flutter 中创建类似 ToggleButton 的 TabBar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65954778/
我想将照片数据从 Tabbarcontroller 中的一个 Viewcontroller(cameraVC) 传递到同一 Tabbarcontroller 中的另一个 Viewcontroller(
我需要加载选项卡栏项目。在这里,我需要不同标签中标签栏的不同背景颜色。我正在更改 didSelectItem 中的栏色调颜色。但它的背景颜色没有改变。加载标签栏时它工作正常。 这是我的代码 over
我想获取标签栏默认大小,但我在ViewController中没有任何tabBar,所以我没有使用self.tabBarController?.tabBar.frame.size.height . 我使
我有一个应用程序的想法,但在使用 Xcode 几个月后,我遇到了一个主要的设计问题。我想要这个: 但正如许多 ios 开发人员所知,在界面构建器中使用传统的标签栏只会创建单色、非轮廓、标签栏按钮,如下
我在我的应用程序上使用 TabBarController,在其中一个主视图 (aViewController) 中,我按下另一个 Controller (bViewController),并使用 se
我想在用户点击选项卡时切换选定的选项卡。假设我有两个选项卡并且显示第一个选项卡,那么点击第一个选项卡(以及点击第二个选项卡)应该会引导我进入第二个选项卡。我已经实现了一个自定义 UITabBarCon
我有一个带有 3 个选项卡的选项卡栏 Controller ,每个选项卡都有导航 Controller ,在每个导航 Controller 的 Root View Controller 上我想要选项卡
我正在编写一个 iPhone 应用程序,它类似于 5-6 级向下钻取应用程序。我几乎完成了我的应用程序的编写,现在提出了一个新要求,即从第三个屏幕开始添加一个 TabBar(JQuery 中的导航栏)
我正在使用 SWRevealViewController 作为侧边菜单。我的应用程序中还有一个标签栏 Controller 作为主视图。 在我的菜单中,我有“MenuItem”(显示MenuItemV
我正在通过 Storyboard 创建一个 TabBar Controller 应用程序。我正在使用 Storyboard 引用对象来链接第三个选项卡项的另一个 Storyboard 。它工作正常,但
TabBar 没有隐藏在推送的 ViewController 中,我使用下面的代码来隐藏 tabBar, tabBarController?.tabBar.isHidden = true
我目前有两个 View Controller ,一个是使用 imagePicker 拍照的 CameraViewController,另一个是显示一个人收到的所有照片消息的 PhotoInboxVie
我有一个包含 5 个项目的 UITabBarController。在其中一个 ViewController 上,我有一个按钮,我将其称为“开始”,所以当我按下开始时,我想插入另一个 ViewContr
我正在更改 setSelectionIndicatorImage,当我在 iOS 8 上运行应用程序时,我得到图像和 tabBar 的常规宽度之间的间距。有没有一种方法可以使标签栏的高度与 setSe
我想通过在图像上向左滑动从“正在显示”导航到“即将推出”,此外,我希望 Appbar 在我滑动时不要移动,但我认为只有标签栏和我不确定,如果您知道如何实现这一点,请提供一些建议 enter image
在我的项目中,我有一个 UITabBarController。在其中一个 ViewControllers 上我有一个按钮。当我单击此按钮时,一个新的 ViewController 将以模态方式呈现。
我是 iPhone 开发新手,多个 View (xib 或 nib)真的让我感到困惑。这就是我想要实现的目标...... 使用 TabBarControllerAppDelegate 有 5 个不同的
滚动到底部后如何修复 iOS 15 标签栏透明: 最佳答案 在 iOS 15 中,Apple 添加了 scrollEdgeAppearance用于在边缘滚动时配置标签栏外观的属性。 https://d
我尝试创建如下图所示的自定义标签栏: 下面是我得到的结果: 以下是我当前的代码: class CustomTabBarController: UITabBarController { over
Widget build(BuildContext context) { return Scaffold( body: SingleChildScrollView( child: Colu
我是一名优秀的程序员,十分优秀!