🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / FLUTTER / Responsive uygulama geliştirme Tasarım Mobil ve Web Uyumlu ve Boyut Esnekliği Design

1-) FLUTTER - Responsive uygulama geliştirme Tasarım Mobil ve Web Uyumlu ve Boyut Esnekliği Design

 

flutter web run

 

flutter run -d chrome --web-renderer html

 

buradan free lere gözat : https://www.flutterlibrary.com/framework/flutter

admin theme go router kullanılabilir : https://www.flutterlibrary.com/templates/responsive-admin-dashboard

 

 

1- cihazı tahmin etme

 

 

import 'package:flutter/material.dart';

class Responsive extends StatelessWidget {
  
final Widget mobile;
  
final Widget? tablet;
  
final Widget desktop;

  
const Responsive({
    
super.key,
    
required this.mobile,
    
this.tablet,
    
required this.desktop,
  });

  
static bool isMobile(BuildContext context) =>
      
MediaQuery.of(context).size.width < 1024;

  
static bool isTablet(BuildContext context) =>
      
MediaQuery.of(context).size.width < 1280 &&
      
MediaQuery.of(context).size.width >= 1024;

  
static bool isDesktop(BuildContext context) =>
      
MediaQuery.of(context).size.width >= 1280;

  
@override
  
Widget build(BuildContext context) {
    
final Size size = MediaQuery.of(context).size;
    
// If our width is more than 1280 then we consider it a desktop
    
if (size.width >= 1280) {
      
return desktop;
    }
    
// If width it less then 1280 and more then 1024 we consider it as tablet
    
else if (size.width >= 904 && tablet != null) {
      
return tablet!;
    }
    
// Or less then that we called it mobile
    
else {
      
return mobile;
    }
  }
}

 

 

 

 

2- kullanımı

 

if (!Responsive.isMobile(context)) gapW16,
Expanded(
  child:
Column(
    crossAxisAlignment:
CrossAxisAlignment.start,
    children: [
      
Text(
        
title,
        style:
Theme.of(context)
            .
textTheme
            
.bodySmall!
            .copyWith(fontWeight:
FontWeight.w600),
      ),
      
Text(
        
amount,
        style:
Responsive.isDesktop(context)
            ?
Theme.of(context)
                .
textTheme
                
.headlineLarge!
                .copyWith(fontWeight:
FontWeight.bold)
            :
Theme.of(context)
                .
textTheme
                
.headlineMedium!
                .copyWith(fontWeight:
FontWeight.bold),
      ),
      
if (Responsive.isMobile(context))
        
Column(
          children: [
            
gapH4,
            
Chip(
              backgroundColor:
isPositiveGrowth

 

 

 

 

body: Container(
constraints: BoxConstraints(
maxWidth: 200, // Maksimum genişlik sınırlaması
),

 

 

LayoutBuilder KULLANIMI

 

 

import 'package:flutter/material.dart';

 

void main() {

  runApp(MyApp());

}

 

class MyApp extends StatelessWidget {

  @override

  Widget build(BuildContext context) {

    return MaterialApp(

      home: Scaffold(

        appBar: AppBar(

          title: Text('LayoutBuilder Örneği'),

        ),

        body: Center(

          child: LayoutBuilder(

            builder: (context, constraints) {

              return Container(

                width: constraints.maxWidth * 0.8,

                height: constraints.maxHeight * 0.5,

                color: Colors.blue,

                child: Center(

                  child: Text(

                    'Esnek Düzen',

                    style: TextStyle(

                      fontSize: 20,

                      color: Colors.white,

                    ),

                  ),

                ),

              );

            },

          ),

        ),

      ),

    );

  }

}

 

 

 

 

Flutter ile responsive tasarım yapmak için birkaç temel prensip ve widget kullanabilirsiniz. Responsive tasarım, uygulamanızın farklı ekran boyutlarına ve yönelimlerine uyum sağlamasını sağlar. İşte Flutter ile responsive tasarım yapmanın bazı yolları:

 

1. MediaQuery Kullanımı

MediaQuery widget'ı, cihazın ekran boyutlarını ve diğer fiziksel özelliklerini elde etmenizi sağlar. Aşağıdaki örnekte, ekran genişliğini kullanarak bir widget'ın boyutunu ayarlayabilirsiniz:

 

dart

Kodu kopyala

import 'package:flutter/material.dart';

 

class ResponsiveLayout extends StatelessWidget {

  @override

  Widget build(BuildContext context) {

    var screenWidth = MediaQuery.of(context).size.width;

 

    return Scaffold(

      appBar: AppBar(title: Text('Responsive Layout')),

      body: Center(

        child: Container(

          width: screenWidth * 0.8, // Ekran genişliğinin %80'i

          height: 200,

          color: Colors.blue,

        ),

      ),

    );

  }

}

2. LayoutBuilder Kullanımı

LayoutBuilder widget'ı, parent widget'ın boyutlarına erişmenizi sağlar ve buna göre farklı widget'lar gösterebilirsiniz:

 

dart

Kodu kopyala

import 'package:flutter/material.dart';

 

class ResponsiveLayout extends StatelessWidget {

  @override

  Widget build(BuildContext context) {

    return Scaffold(

      appBar: AppBar(title: Text('Responsive Layout')),

      body: LayoutBuilder(

        builder: (context, constraints) {

          if (constraints.maxWidth < 600) {

            return Column(

              children: [

                Text('Small Screen'),

                Container(

                  height: 100,

                  color: Colors.red,

                ),

              ],

            );

          } else {

            return Row(

              children: [

                Expanded(

                  child: Container(

                    height: 100,

                    color: Colors.red,

                  ),

                ),

                Expanded(

                  child: Container(

                    height: 100,

                    color: Colors.green,

                  ),

                ),

              ],

            );

          }

        },

      ),

    );

  }

}

3. Flexible ve Expanded Kullanımı

Flexible ve Expanded widget'ları, widget'ların esnekliğini ve ekran boyutlarına göre nasıl genişleyeceklerini kontrol etmenizi sağlar:

 

dart

Kodu kopyala

import 'package:flutter/material.dart';

 

class ResponsiveLayout extends StatelessWidget {

  @override

  Widget build(BuildContext context) {

    return Scaffold(

      appBar: AppBar(title: Text('Responsive Layout')),

      body: Row(

        children: [

          Expanded(

            flex: 2,

            child: Container(

              height: 100,

              color: Colors.red,

            ),

          ),

          Expanded(

            flex: 1,

            child: Container(

              height: 100,

              color: Colors.green,

            ),

          ),

        ],

      ),

    );

  }

}

4. OrientationBuilder Kullanımı

OrientationBuilder widget'ı, cihazın yönelimini kontrol eder ve farklı yönelimlere göre farklı düzenler sunar:

 

dart

Kodu kopyala

import 'package:flutter/material.dart';

 

class ResponsiveLayout extends StatelessWidget {

  @override

  Widget build(BuildContext context) {

    return Scaffold(

      appBar: AppBar(title: Text('Responsive Layout')),

      body: OrientationBuilder(

        builder: (context, orientation) {

          if (orientation == Orientation.portrait) {

            return Column(

              children: [

                Text('Portrait Mode'),

                Container(

                  height: 100,

                  color: Colors.blue,

                ),

              ],

            );

          } else {

            return Row(

              children: [

                Text('Landscape Mode'),

                Container(

                  height: 100,

                  color: Colors.orange,

                ),

              ],

            );

          }

        },

      ),

    );

  }

}

Bu teknikler ve widget'lar, Flutter ile responsive tasarımlar oluşturmanıza yardımcı olacaktır. Uygulamanızın kullanıcı deneyimini iyileştirmek için bu yöntemleri projelerinizde kullanabilirsiniz.

 

 2024 Haziran 13 Perşembe
 454