Как заставить TabBarView соответствовать размеру своих дочерних элементов? - PullRequest
0 голосов
/ 14 июля 2020

Я пытаюсь реализовать TabBarView, который должен занимать размер своих дочерних элементов. Я последовал за другими ответами здесь и обернул TabBarView с расширенным виджетом. Но если я это сделаю, я получу следующую ошибку. Я попытался сделать то, о чем мне говорила ошибка, и обернул ее с помощью Flexible (), но в итоге я получил другую ошибку. Может ли кто-нибудь помочь мне с этим? Заранее спасибо!

RenderFlex children have non-zero flex but incoming height constraints
are unbounded. When a column is in a parent that does not provide a
finite height constraint, for example if it is in a vertical
scrollable, it will try to shrink-wrap its children along the vertical
axis. Setting a flex on a child (e.g. using Expanded) indicates that
the child is to expand to fill the remaining space in the vertical
direction. These two directives are mutually exclusive. If a parent is
to shrink-wrap its child, the child cannot simultaneously expand to
fit its parent. Consider setting mainAxisSize to MainAxisSize.min and
using FlexFit.loose fits for the flexible children (using Flexible
rather than Expanded). This will allow the flexible children to size
themselves to less than the infinite remaining space they would
otherwise be forced to take, and then will cause the RenderFlex to
shrink-wrap the children rather than expanding to fit the maximum
constraints provided by the parent.
class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage>
    with SingleTickerProviderStateMixin {
  final TextEditingController prefixController = TextEditingController();

  String url = "xyz.com";

  final List<String> myData = [];

  Future<String> makeRequest() async {
    print("Getting data from API...");
    var response = await http
        .get(Uri.encodeFull(url), headers: {"Accept": "application/json"});

    var extractdata = jsonDecode(response.body);

    String data = extractdata['text'];

    //print(data);

    setState(() {
      myData.add(data);
    });

    print(myData);
  }

  TabController _tabController;
  @override
  void initState() {
    super.initState();
    _tabController = TabController(
      length: 2,
      vsync: this,
    );
  }

  @override
  Widget build(BuildContext context) {
    final mediaQuery = MediaQuery.of(context);
    bool isDesktop = mediaQuery.size.width > 500 ? true : false;

    return Scaffold(
        backgroundColor: Color(0xFF15202b),
        body: LayoutBuilder(builder: (ctx, constraints) {
          return SingleChildScrollView(
            child: Padding(
              padding: EdgeInsets.all(32),
              child: Container(
                alignment: Alignment.center,
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: <Widget>[
                    SizedBox(
                      height: 15,
                    ),
                    Container(
                        width: isDesktop ? 500 : mediaQuery.size.width * 1,
                        decoration: BoxDecoration(
                            border: Border(
                                top: BorderSide(width: 0.5, color: Colors.grey),
                                left:
                                    BorderSide(width: 0.5, color: Colors.grey),
                                right: BorderSide(
                                    width: 0.5, color: Colors.grey))),
                        child: Bio(ctx: ctx)),
                    Column(
                      children: [
                        Container(
                          decoration: BoxDecoration(
                              border: Border(
                                  left: BorderSide(
                                      width: 0.5, color: Colors.grey),
                                  right: BorderSide(
                                      width: 0.5, color: Colors.grey))),
                          width: isDesktop ? 500 : mediaQuery.size.width * 1,
                          child: TabBar(
                              controller: _tabController,
                              tabs: [Tab(text: "Tweets"), Tab(text: "About")]),
                        ),
                        Expanded(
                          child:
                              TabBarView(controller: _tabController, children: [
                            TweetScreen(myData, isDesktop, mediaQuery),
                            About(),
                          ]),
                        ),
                      ],
                    ),
                    //Text(myData[0]),
                  ],
                ),
              ),
            ),
          );
        }),
        floatingActionButton: FloatingActionButton(
          onPressed: makeRequest,
          child: Icon(Icons.add),
        ));
  }
}
...