Skip to content
TheChatArchiveThe Chat Archive
gpt-4-0125-preview· OpenAIAi2 WildChat-4.8M (AI2)

je veux que les deux boutons soient toujours à une position fixe sur l’écran (en bas),…

  1. User

    je veux que les deux boutons soient toujours à une position fixe sur l’écran (en bas), je veux que le reste soit scrollable s’il y a de l’overflow.

    import 'package:allo/utils/bottom_round_clipper.dart'; import 'package:flutter/material.dart';

    class RegisterPage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( body: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ ClipPath( clipper: BottomRoundClipper(), child: Container( color: Color(0xFFD9D9D9), child: Transform.translate( offset: Offset(10, -55), // décale l'image de 50 pixels vers le haut child: Transform.scale( scale: 1.2, // zoom sur l'image (1.0 est la taille normale) child: Image.asset( 'assets/register.png', fit: BoxFit .fill, // remplir le conteneur (peut recadrer l'image) ), ), ), ), ), Padding( padding: EdgeInsets.all(20.0), child: Form( child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Text( 'M'inscrire', style: TextStyle( fontSize: 24.0, fontWeight: FontWeight.bold, ), ), SizedBox( height: 20.0), // espace entre le titre et le premier champ de texte TextFormField( decoration: InputDecoration( labelText: 'Email', ), ), SizedBox(height: 20.0), // espace entre les champs de texte TextFormField( decoration: InputDecoration( labelText: 'Nom d'utilisateur', ), ), SizedBox(height: 20.0), // espace entre les champs de texte TextFormField( decoration: InputDecoration( labelText: 'Mot de passe', ), obscureText: true, // cache le mot de passe ), SizedBox( height: 20.0), // espace entre le dernier champ de texte et les boutons Row( mainAxisAlignment: MainAxisAlignment .spaceEvenly, // aligne les boutons horizontalement avec un espace égal entre eux children: [ Expanded( child: Padding( padding: const EdgeInsets.all(8.0), child: ElevatedButton( onPressed: () { print('Button 1'); }, style: ButtonStyle( backgroundColor: MaterialStateProperty.all(Color(0xFFD4D7EC)), ), child: Text( 'Me connecter', style: TextStyle( color: Color(0xFF0F0D11), fontSize: 18.0, ), ), ), ), ), Expanded( child: Padding( padding: const EdgeInsets.all(8.0), child: ElevatedButton( onPressed: () { print('Button 2'); }, style: ButtonStyle( backgroundColor: MaterialStateProperty.all(Color(0xFFD4D7EC)), ), child: Text( 'M'inscrire', style: TextStyle( color: Color(0xFF0F0D11), fontSize: 18.0, ), ), ), ), ), ], ), ], ), ), ), ], ), ); } }

  2. Assistant

    Pour réaliser le comportement que vous désirez (fixer les boutons en bas et rendre le reste scrollable en cas de dépassement), vous pouvez utiliser une combinaison de SingleChildScrollView et Column dans un stack avec un Column pour les boutons en bas de l'écran. Voici comment vous pouvez ajuster votre code :

    import 'package:flutter/material.dart';
    import 'package:allo/utils/bottom_round_clipper.dart';
    
    class RegisterPage extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Stack( // Utiliser un Stack pour superposer les éléments
            children: [
              SingleChildScrollView( // Rendre le contenu principal scrollable
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: [
                    ClipPath(
                      clipper: BottomRoundClipper(),
                      child: Container(
                        color: Color(0xFFD9D9D9),
                        child: Transform.translate(
                          offset: Offset(10, -55),
                          child: Transform.scale(
                            scale: 1.2,
                            child: Image.asset(
                              'assets/register.png',
                              fit: BoxFit.fill,
                            ),
                          ),
                        ),
                      ),
                    ),
                    Padding(
                      padding: EdgeInsets.all(20.0),
                      child: Form(
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.stretch,
                          children: [
                            Text(
                              'M\'inscrire',
                              style: TextStyle(
                                fontSize: 24.0,
                                fontWeight: FontWeight.bold,
                              ),
                            ),
                            SizedBox(height: 20.0),
                            TextFormField(
                              decoration: InputDecoration(labelText: 'Email'),
                            ),
                            SizedBox(height: 20.0),
                            TextFormField(
                              decoration: InputDecoration(labelText: 'Nom d\'utilisateur'),
                            ),
                            SizedBox(height: 20.0),
                            TextFormField(
                              decoration: InputDecoration(labelText: 'Mot de passe'),
                              obscureText: true,
                            ),
                            SizedBox(height: 20.0), // Un espace supplémentaire pour s'assurer que le contenu ne soit pas caché par les boutons
                          ],
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              Align( // Positionner les boutons en bas de l'écran
                alignment: Alignment.bottomCenter,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: [
                    Expanded(
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: ElevatedButton(
                          onPressed: () {},
                          style: ButtonStyle(backgroundColor: MaterialStateProperty.all(Color(0xFFD4D7EC))),
                          child: Text('Me connecter', style: TextStyle(color: Color(0xFF0F0D11), fontSize: 18.0)),
                        ),
                      ),
                    ),
                    Expanded(
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: ElevatedButton(
                          onPressed: () {},
                          style: ButtonStyle(backgroundColor: MaterialStateProperty.all(Color(0xFFD4D7EC))),
                          child: Text('M\'inscrire', style: TextStyle(color: Color(0xFF0F0D11), fontSize: 18.0)),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        );
      }
    }
    

    Ce que nous avons fait ici :

    1. Nous avons enveloppé le contenu principal dans un SingleChildScrollView pour le rendre scrollable.
    2. Les boutons ont été placés dans un Align avec Alignment.bottomCenter pour qu'ils soient toujours fixés au bas de l'écran, à l'intérieur d'un Stack.
    3. Cette approche maintiendra les boutons au bas de l'écran, quel que soit la quantité de contenu dans le SingleChildScrollView.
  3. User

    je veux que les boutons soient tout en bas de l'écran comme on pourrait le faire avec un position fixed en css sur du web mais là avec mon code les boutons sont juste en dessous du dernier textfield du form.

    import 'package:allo/utils/bottom_round_clipper.dart'; import 'package:flutter/material.dart';

    class RegisterPage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( body: LayoutBuilder( builder: (BuildContext context, BoxConstraints constraints) { return Stack( children: [ SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Container( height: constraints.maxHeight * 0.4, // 30% de la hauteur de l'écran child: ClipPath( clipper: BottomRoundClipper(), child: Transform.translate( offset: Offset(0, 0), child: Transform.scale( scale: 1.2, child: Image.asset( 'assets/register.png', fit: BoxFit .fill, // remplir le conteneur (peut recadrer l'image) ), ), ), ), ), Padding( padding: EdgeInsets.all(20.0), child: Form( child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Text( 'M'inscrire', style: TextStyle( fontSize: 24.0, fontWeight: FontWeight.bold, ), ), SizedBox( height: 20.0), // espace entre le titre et le premier champ de texte TextFormField( decoration: InputDecoration( labelText: 'Email', ), ), SizedBox( height: 20.0), // espace entre les champs de texte TextFormField( decoration: InputDecoration( labelText: 'Nom d'utilisateur', ), ), SizedBox( height: 20.0), // espace entre les champs de texte TextFormField( decoration: InputDecoration( labelText: 'Mot de passe', ), obscureText: true, // cache le mot de passe ), SizedBox( height: 20.0), // espace entre le dernier champ de texte et les boutons ], ), ), ), ], ), ), Positioned( bottom: 0, left: 0, right: 0, child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Expanded( child: Padding( padding: const EdgeInsets.all(8.0), child: ElevatedButton( onPressed: () { print('Button 1'); }, style: ButtonStyle( backgroundColor: MaterialStateProperty.all(Color(0xFFD4D7EC)), ), child: Text( 'Me connecter', style: TextStyle( color: Color(0xFF0F0D11), fontSize: 18.0, ), ), ), ), ), Expanded( child: Padding( padding: const EdgeInsets.all(8.0), child: ElevatedButton( onPressed: () { print('Button 2'); }, style: ButtonStyle( backgroundColor: MaterialStateProperty.all(Color(0xFFD4D7EC)), ), child: Text( 'M'inscrire', style: TextStyle( color: Color(0xFF0F0D11), fontSize: 18.0, ), ), ), ), ), ], ), ), ], ); }, ), ); } }

  4. Assistant

    Votre implémentation actuelle place déjà les boutons au bas de l'écran grâce à l'utilisation de la combinaison Stack et Positioned. Cependant, il semble y avoir une confusion quant à pourquoi les boutons ne restent pas visibles tout en bas de l'écran lorsque le contenu devient scrollable et occupé plus d'espace que la hauteur de l'écran lui-même.

    Le comportement observé est normal compte tenu de votre structure de code actuelle. La Stack place les boutons au bas de son contenu, mais l'écran ne peut afficher les boutons fixés au bas uniquement lorsque le contenu de SingleChildScrollView n'excède pas la hauteur de l'écran.

    Pour s'assurer que les boutons restent visiblement fixés au bas de l'écran tout en gardant le reste du contenu scrollable, vous devriez avoir un layout qui permet au SingleChildScrollView d'occuper tout l'espace disponible au-dessus des boutons, et non pas le reste de l'écran en entier. Les boutons, d'un autre côté, devraient être placés hors du scrollable area, mais toujours à l'intérieur du layout principal.

    Un moyen très simple d'y parvenir est d'utiliser une Column racine dans laquelle vous divisez l'écran entre le contenu scrollable et la section des boutons, comme suit:

    import 'package:flutter/material.dart';
    import 'package:allo/utils/bottom_round_clipper.dart';
    
    class RegisterPage extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: LayoutBuilder(
            builder: (BuildContext context, BoxConstraints constraints) {
              return Column( // Utilisez Column à la place de Stack
                children: [
                  Expanded( // Contenu scrollable occupe tout l'espace disponible
                    child: SingleChildScrollView(
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.stretch,
                        children: [
                          Container(
                            height: constraints.maxHeight * 0.4,
                            child: ClipPath(
                              clipper: BottomRoundClipper(),
                              child: Transform.translate(
                                offset: Offset(0, 0),
                                child: Image.asset(
                                  'assets/register.png',
                                  fit: BoxFit.fill,
                                ),
                              ),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.all(20.0),
                            child: Form(
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.stretch,
                                children: [
                                  Text('M\'inscrire', style: TextStyle(fontSize: 24.0, fontWeight: FontWeight.bold)),
                                  SizedBox(height: 20.0),
                                  TextFormField(decoration: InputDecoration(labelText: 'Email')),
                                  SizedBox(height: 20.0),
                                  TextFormField(decoration: InputDecoration(labelText: 'Nom d\'utilisateur')),
                                  SizedBox(height: 20.0),
                                  TextFormField(decoration: InputDecoration(labelText: 'Mot de passe'), obscureText: true),
                                  SizedBox(height: 20.0), // Espace supplémentaire facultatif
                                ],
                              ),
                            ),
                          ),
                          SizedBox(height: 50), // du buffer si nécessaire
                        ],
                      ),
                    ),
                  ),
                  // Section des boutons toujours visible au bas de l'écran
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: [
                      Expanded(
                        child: Padding(
                          padding: const EdgeInsets.all(8.0),
                          child: ElevatedButton(
                            onPressed: () {},
                            style: ButtonStyle(backgroundColor: MaterialStateProperty.all(Color(0xFFD4D7EC))),
                            child: Text('Me connecter', style: TextStyle(color: Color(0xFF0F0D11), fontSize: 18.0)),
                          ),
                        ),
                      ),
                      Expanded(
                        child: Padding(
                          padding: const EdgeInsets.all(8.0),
                          child: ElevatedButton(
                            onPressed: () {},
                            style: ButtonStyle(backgroundColor: MaterialStateProperty.all(Color(0xFFD4D7EC))),
                            child: Text('M\'inscrire', style: TextStyle(color: Color(0xFF0F0D11), fontSize: 18.0)),
                          ),
                        ),
                      ),
                    ],
                  ),
                ],
              );
            },
          ),
        );
      }
    }
    

    Cette méthode s'assure que peu importe le contenu de votre ScrollView, les boutons seront toujours affichés fixement en bas de l'écran.