top of page

Layout Cheat Sheet für Flutter auf deutsch

  • Autorenbild: Flutter Akademie
    Flutter Akademie
  • 5. Okt. 2022
  • 2 Min. Lesezeit

ree

Flutter lernen ist sehr einfach. Und mit diesem Layout Cheat Sheet ist es noch einfacher schöne Apps in Flutter zu bauen. Dieser Artikel wird euch helfen, euer UI unter Kontrolle zu bringen, damit die Layout Gestaltung in Flutter noch einfacher wird.


Übersicht

  • Row und Columns

  • ConstrainedBox

  • BoxDecoration


Row und Column


Bei der Ausrichtung der Objekte benutzt Flutter das gleiche System wie auch Bootstrap. Hier hängt man an das Objekt den Zusatz start, end, center, spaceBetween usw an.


MainAxisAlignment.start

Row /*or Column*/( 
  mainAxisAlignment: MainAxisAlignment.start,
  children: <Widget>[
    Icon(Icons.star, size: 50),
    Icon(Icons.star, size: 50),
    Icon(Icons.star, size: 50),
  ],
),

ree

MainAxisAlignment.center

Row /*or Column*/( 
  mainAxisAlignment: MainAxisAlignment.center,
  children: <Widget>[
    Icon(Icons.star, size: 50),
    Icon(Icons.star, size: 50),
    Icon(Icons.star, size: 50),
  ],
),


ree

MainAxisAlignment.end

Row /*or Column*/( 
  mainAxisAlignment: MainAxisAlignment.end,
  children: <Widget>[
    Icon(Icons.star, size: 50),
    Icon(Icons.star, size: 50),
    Icon(Icons.star, size: 50),
  ],
),

ree

MainAxisAlignment.spaceBetween

Row /*or Column*/( 
  mainAxisAlignment: MainAxisAlignment.spaceBetween,
  children: <Widget>[
    Icon(Icons.star, size: 50),
    Icon(Icons.star, size: 50),
    Icon(Icons.star, size: 50),
  ],
),

ree

MainAxisAlignment.spaceEvenly

Row /*or Column*/( 
  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  children: <Widget>[
    Icon(Icons.star, size: 50),
    Icon(Icons.star, size: 50),
    Icon(Icons.star, size: 50),
  ],
),

ree

MainAxisAlignment.spaceAround

Row /*or Column*/( 
  mainAxisAlignment: MainAxisAlignment.spaceAround,
  children: <Widget>[
    Icon(Icons.star, size: 50),
    Icon(Icons.star, size: 50),
    Icon(Icons.star, size: 50),
  ],
),

ree

ConstrainedBox

Mit ConstrainedBox nutzt ein Widget allen verfügbaren Platz.

ConstrainedBox( 
  constraints: BoxConstraints.expand(),
  child: const Card(
    child: const Text('Hello World!'), 
    color: Colors.yellow,
  ), 
),

ree

Mit BoxConstraints kannst du beeinflussen, wie viel Platz ein Widget einnimmt. Hier stehen dir die Zusätze: min/max/height/width.


ConstrainedBox(
  constraints: BoxConstraints.expand(height: 300),
  child: const Card(
    child: const Text('Hello World!'), 
    color: Colors.yellow,
  ),
),

ree

oder:


ConstrainedBox(
  constraints: BoxConstraints(
    minWidth: double.infinity,
    maxWidth: double.infinity,
    minHeight: 300,
    maxHeight: 300,
  ),
  child: const Card(
    child: const Text('Hello World!'), 
    color: Colors.yellow,
  ),
),

ree

BoxDecoration


Mit BoxDecoration kannst du das Aussehen des Containers verändern.


DecorationImage


Verschiebt ein Bild in den Hintergrund.

Scaffold(
  appBar: AppBar(title: Text('image: DecorationImage')),
  body: Center(
    child: Container(
      height: 200,
      width: 200,
      decoration: BoxDecoration(
        color: Colors.yellow,
        image: DecorationImage(
          fit: BoxFit.fitWidth,
          image: NetworkImage(
            'https://flutter.io/images/catalog-widget-placeholder.png',
          ),
        ),
      ),
    ),
  ),
);

ree

Border


Scaffold(
  appBar: AppBar(title: Text('border: Border')),
  body: Center(
    child: Container(
      height: 200,
      width: 200,
      decoration: BoxDecoration(
        color: Colors.yellow,
        border: Border.all(color: Colors.black, width: 3),
      ),
    ),
  ),
);

ree

BorderRadius


Scaffold(
  appBar: AppBar(title: Text('borderRadius: BorderRadius')),
  body: Center(
    child: Container(
      height: 200,
      width: 200,
      decoration: BoxDecoration(
        color: Colors.yellow,
        border: Border.all(color: Colors.black, width: 3),
        borderRadius: BorderRadius.all(Radius.circular(18)),
      ),
    ),
  ),
);

ree

BoxShape


Scaffold(
  appBar: AppBar(title: Text('shape: BoxShape')),
  body: Center(
    child: Container(
      height: 200,
      width: 200,
      decoration: BoxDecoration(
        color: Colors.yellow,
        shape: BoxShape.circle,
      ),
    ),
  ),
);


ree

boxShadow


Scaffold(
  appBar: AppBar(title: Text('boxShadow: List<BoxShadow>')),
  body: Center(
    child: Container(
      height: 200,
      width: 200,
      decoration: BoxDecoration(
        color: Colors.yellow,
        boxShadow: const [
          BoxShadow(blurRadius: 10),
        ],
      ),
    ),
  ),
);


ree

Gradient


Man unterscheidet drei Arten von Gradienten: LinearGradient, RadialGradientund SweepGradient. Hier sei beispielhaft der LinearGradient aufgeführt.


Scaffold(
  appBar: AppBar(title: Text('gradient: LinearGradient')),
  body: Center(
    child: Container(
      height: 200,
      width: 200,
      decoration: BoxDecoration(
        gradient: LinearGradient(
          colors: const [
            Colors.red,
            Colors.blue,
          ],
        ),
      ),
    ),
  ),
);
ree

Ich werde den Cheat Sheet Artikel noch erweitern, aber erst einmal sind die Grundlagen gedeckt.



 
 
 

Aktuelle Beiträge

Alle ansehen
Numerische Eingabefelder in Flutter

Wenn du eine Flutter-App entwickelst, wirst du oft Eingabefelder (TextFormFields) benötigen, die nur numerische Eingaben erlauben. Ob für...

 
 
 
bottom of page