Flutter-如何制作自定义TabBar

时间:2020-08-08 09:58:36

标签: flutter dart flutter-layout

My Image

这是我想要的输出。我还是扑朔迷离,所以任何人都可以让我知道是否已经有这种开关的小部件,或者我应该怎么做? 另外,如果我选择另一个按钮,我希望该按钮下面显示的数据发生变化,但是我想这很明显。

谢谢。

2 个答案:

答案 0 :(得分:2)

您可以使用BufferedInputStream bis = new BufferedInputStream(socket.getInputStream()); BufferedOutputStream dataOut = new BufferedOutputStream(socket.getOutputStream()); PrintWriter out = new PrintWriter(socket.getOutputStream()); String input = ""; while (true) { byte[] data = new byte[10000]; int size = bis.read(data); if (size == -1) break; for (int i = 0; i < size; i++) { char c = (char)data[i]; if (c != '\n') { input += c; } else { if (image_data == false) { System.out.println(input); if (input.contains("Content-Type: image/jpeg")) { image_data = true; } } else { if (input.contains("-----")) { int dsize = string.length() / 1024; System.out.print("file size: " + dsize); System.out.print("string size: " + string.length()); SaveToFile("mydata.jpg", string); image_data = false; System.out.println("upload complete"); break; } else { string += input; } } } } } 小部件来实现此目的。我添加了一个完整的示例,演示如何使用TabBar小部件创建此示例:

CODE

TabBar

输出 output

答案 1 :(得分:0)

尝试一下,您必须change一些colourfont:-

import 'package:flutter/material.dart';

typedef SwitchOnChange = Function(int);

class CustomSwitch extends StatefulWidget {
  SwitchOnChange onChange;

  CustomSwitch({this.onChange});

  @override
  State<StatefulWidget> createState() {
    return CustomSwitchState();
  }
}

class CustomSwitchState extends State<CustomSwitch>
    with TickerProviderStateMixin {
  AnimationController controller;
  Animation animation;

  GlobalKey key = GlobalKey();
  @override
  void initState() {
    Future.delayed(Duration(milliseconds: 100)).then((v) {
      controller = AnimationController(
          vsync: this, duration: Duration(milliseconds: 300));

      tabWidth = key.currentContext.size.width / 2;
      // var width = (media.size.width - (2 * media.padding.left)) / 2;
      animation = Tween<double>(begin: 0, end: tabWidth).animate(controller);

      setState(() {});

      controller.addListener(() {
        setState(() {});
      });
    });
    super.initState();
  }

  var selectedValue = 0;
  double tabWidth = 0;
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        selectedValue == 0 ? this.controller.forward() : controller.reverse();
        selectedValue = selectedValue == 0 ? 1 : 0;
      },
      child: Container(
        key: key,
        height: 44,
        decoration: BoxDecoration(
            color: Colors.grey, borderRadius: BorderRadius.circular(22)),
        child: Stack(
          children: <Widget>[
            Row(
              children: <Widget>[
                Transform.translate(
                  offset: Offset(animation?.value ?? 0, 0),
                  child: Container(
                    height: 44,
                    width: tabWidth,
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(22),
                        boxShadow: [
                          BoxShadow(color: Colors.grey, blurRadius: 3),
                        ]),
                  ),
                ),
              ],
            ),
            Center(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Container(
                    width: tabWidth,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        Icon(Icons.directions_walk),
                        SizedBox(width: 5),
                        Text("Place Bid")
                      ],
                    ),
                  ),
                  Container(
                    width: tabWidth,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        Icon(Icons.directions_walk),
                        SizedBox(width: 5),
                        Text("Buy now")
                      ],
                    ),
                  )
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}