8
votes

Conteneur pleine hauteur à l'intérieur de SingleChildScrollView

J'ai un SingleChildScrollView et à l'intérieur un Container . Ce que je veux, c'est que la hauteur d'un Container soit une hauteur de fenêtre complète.

Mon code:

I/flutter ( 6293): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter ( 6293): The following assertion was thrown during performLayout():
I/flutter ( 6293): BoxConstraints forces an infinite height.
I/flutter ( 6293): These invalid constraints were provided to RenderDecoratedBox's layout() function by the following
I/flutter ( 6293): function, which probably computed the invalid constraints in question:
I/flutter ( 6293):   RenderConstrainedBox.performLayout (package:flutter/src/rendering/proxy_box.dart:258:13)
I/flutter ( 6293): The offending constraints were:
I/flutter ( 6293):   BoxConstraints(w=411.4, h=Infinity)

Si j'exécute mon code , J'ai une exception:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'MyApp',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
        fontFamily: 'OpenSans',
      ),
      home: SingleChildScrollView(
        child: Container(
          color: Colors.white,
          height: double.infinity,
        ),
      ),
    );
  }
}


0 commentaires

3 Réponses :


10
votes

Peut-être

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final mq = MediaQueryData.fromWindow(window);
    return MaterialApp(
      title: 'MyApp',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
        fontFamily: 'OpenSans',
      ),
      home: SingleChildScrollView(
        child: ConstrainedBox(
          constraints: BoxConstraints.tightFor(
            height: mq.size.height,
          ),
          child: Container(
            height: double.infinity,
            decoration: BoxDecoration(
                color: Colors.red,
                border: Border.all(color: Colors.blue, width: 8)),
          ),
        ),
      ),
    );
  }
}


1 commentaires

Comment pourrions-nous contraindre la hauteur d'une pile à l'intérieur de SingleScrollChildView?



6
votes

J'ai eu le même problème mais la réponse n'a pas fonctionné pour moi, donc je devais envelopper le SingleChildScrollView () dans le conteneur et lui donner la hauteur: double.infinity

Container(
    height: double.infinity,
    color: Colors.green,
    child: SingleChildScrollView()
 )


0 commentaires

0
votes

vous pouvez essayer SliverFillViewport ou PageView


0 commentaires