पैकेज, रिपॉज़िटरी और ऐप श्रेणियाँ खोजें

पैकेज विवरणv1.2.0

after_layout

अपने विजेट के पहले लेआउट के बाद कोड निष्पादित करें, अर्थात पहले फ्रेम के प्रदर्शन के बाद।

AndroidiOSWebmacOSWindowsLinux
30-दिन डाउनलोड
2.4 लाख
लाइक
778
Pub अंक
160

पैकेज इंस्टॉल करें

flutter pub add after_layout

पैकेज अवलोकन

सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।

after_layout पैकेज विकासकर्ताओं को एक विजेट के पहले लेआउट पास के बाद तुरंत कोड निष्पादित करने की अनुमति देता है, जिससे विजेट के स्क्रीन पर रेंडर करने के बाद सटीक आयाम और स्थिति तक पहुँच सुनिश्चित होती है। यह ऐनिमेशन, स्थिति समायोजन या अन्य UI घटकों के साथ एकीकरण जैसे अंतिम लेआउट माप के आधार पर कार्य करने के लिए विशेष रूप से उपयोगी है। यह पैकेज Flutter द्वारा समर्थित सभी प्रमुख प्लेटफॉर्मों पर काम करता है, जिसमें मोबाइल, वेब और डेस्कटॉप शामिल हैं। यह किसी भी StatefulWidget में जोड़ा जा सकने वाले मिक्सिन के माध्यम से एक सरल API प्रदान करता है।

उपयोग

  • पोस्ट-लेआउट एनिमेशन चला रहे हैं
  • वास्तविक आकार के आधार पर विजेट स्थिति में समायोजन
  • लेआउट डेटा की आवश्यकता वाले तृतीय पक्ष के लाइब्रेरी को शुरू करना
  • रेंडर के बाद UI तत्वों को समकालिक करना
  • डायनामिक सामग्री आकार का प्रबंधन

मुख्य विशेषताएँ

  • सरल mixin-आधारित API
  • क्रॉस-प्लेटफ़ॉर्म संगतता
  • पहले फ्रेम के बाद एक बार निष्पादित करता है
  • टाइमर या कॉलबैक की आवश्यकता नहीं है
  • StatefulWidget के साथ काम करता है

इनके लिए उपयुक्त

  • सटीक लेआउट समय की आवश्यकता वाले विकासकर्ता
  • गतिशील लेआउट वाले UI-भारी एप्लिकेशन
  • रेंडरिंग के बाद ट्रिगर होने वाली एनिमेशन
  • लेआउट जागरूकता की आवश्यकता वाले कस्टम विजेट्स

विचार योग्य बातें

  • दोहराए गए लेआउट इवेंट्स के लिए उपयुक्त नहीं
  • गलत उपयोग करने पर प्रदर्शन में समस्या हो सकती है
  • राज्य-संवेदी विंडगेट संदर्भ की आवश्यकता होती है
  • प्रत्येक विजेट उदाहरण के लिए एक ही निष्पादन सीमित
  • पहले बिल्ड के पहले काम नहीं करता है

मूल README

संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।

Flutter Community: after_layout

Flutter After Layout

pub package

Brings functionality to execute code after the first layout of a widget has been performed, i.e. after the first frame has been displayed.

Quick Usage

Add with AfterLayoutMixin<MyWidget> mixin to your State<MyWidget> class and then implement the FutureOr<void> afterFirstLayout(BuildContext context) abstract method. Code in this method will be called the first time this widget is laid out on the screen.

Motivation

If you want to display a widget that depends on the layout, such as a Dialog or BottomSheet, you can not use that widget in initState.

You might have tried this.

BAD CODE

import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

@immutable
class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'After Layout - Good Example',
      home: HomeScreen(),
    );
  }
}

@immutable
class HomeScreen extends StatefulWidget {
  const HomeScreen({Key? key}) : super(key: key);

  @override
  HomeScreenState createState() => HomeScreenState();
}

class HomeScreenState extends State<HomeScreen> {
  @override
  void initState() {
    super.initState();
    // NOTE: Calling this function here would crash the app.
    showHelloWorld();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(color: Colors.red),
    );
  }

  void showHelloWorld() {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          content: const Text('Hello World'),
          actions: <Widget>[
            TextButton(
              onPressed: () => Navigator.of(context).pop(),
              child: const Text('DISMISS'),
            )
          ],
        );
      },
    );
  }
}

Usage

This demo showcases how this package resolves the shortcomings shown above:

GOOD CODE

import 'package:flutter/material.dart';
import 'package:after_layout/after_layout.dart';

void main() => runApp(const MyApp());

@immutable
class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'After Layout - Good Example',
      home: HomeScreen(),
    );
  }
}

@immutable
class HomeScreen extends StatefulWidget {
  const HomeScreen({Key? key}) : super(key: key);

  @override
  HomeScreenState createState() => HomeScreenState();
}

class HomeScreenState extends State<HomeScreen> with AfterLayoutMixin<HomeScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(color: Colors.red),
    );
  }

  @override
  void afterFirstLayout(BuildContext context) {
    // Calling the same function "after layout" to resolve the issue.
    showHelloWorld();
  }

  void showHelloWorld() {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          content: const Text('Hello World'),
          actions: <Widget>[
            TextButton(
              onPressed: () => Navigator.of(context).pop(),
              child: const Text('DISMISS'),
            )
          ],
        );
      },
    );
  }
}

श्रेणियाँ

सोर्स रिपॉज़िटरी

इस पैकेज का उपयोग करने वाले प्रोजेक्ट