Toast, Switch

Flutter कोई Toast ship नहीं करता: ScaffoldMessenger के through SnackBar native passing message है (fluttertoast package route है), और Switch controlled-widget law का चौथा witness है, settings flip करते हुए जो immediately act करती हैं।

10 min read · 9 cards · 2 checks

Read in: English · हिन्दी · ગુજરાતી


Theory

बिना किसी को रोके कहिए

Booking saved। User को पता होना चाहिए: पर पिछले lesson का dialog rude होगा: एक mere FYI के लिए एक modal interrogation।

Android ने यह साल पहले Toast से solve किया था: एक छोटा passing message जो खुद dismiss होता है। आपका syllabus Flutter का version माँगता है: और यहाँ एक honesty checkpoint wait करता है जो memorise करने वाले students को जानने वाले students से अलग करता है: Flutter के पास कोई built-in Toast widget बिल्कुल नहीं है। इसके पास जो है वह arguably बेहतर है।

Theory

SnackBar: Flutter का Native Passing Message

Toast-shaped news के लिए Flutter idiom है SnackBar: एक strip जो bottom से slide up होता है, wait करता है, और चला जाता है:

ScaffoldMessenger.of(context).showSnackBar(

SnackBar(

content: Text('Booking saved'),

duration: Duration(seconds: 2),

),

);

ScaffoldMessenger dispatcher है (एक वजह screens Scaffold से शुरू होती हैं: लesson जो pay करता रहता है)। और एक SnackBar एक power carry करता है जो toast के पास कभी नहीं थी: एक action: famous UNDO।

Practical

Saved, Politely कहा गया, एक Exit के साथ

void onBookingSaved() {
  ScaffoldMessenger.of(context).showSnackBar(
    SnackBar(
      content: const Text('Garba Night booked!'),
      duration: const Duration(seconds: 3),
      action: SnackBarAction(          // the power a Toast never had
        label: 'UNDO',
        onPressed: () { /* release the seat */ },
      ),
    ),
  );
}

// The reminders setting: Switch, the controlled law's 4th witness
bool reminders = true;

SwitchListTile(
  title: const Text('Event reminders'),
  value: reminders,
  onChanged: (v) {
    setState(() { reminders = v; });   // flips AND takes effect now
  },
)

Theory

Switch: वही Machinery, अलग Promise

Mechanically, Switch Checkbox का twin है: value: एक bool, onChanged: + setState, null disable करता है: controlled-widget law चौथी बार testify कर रही है। SwitchListTile labelled-row form है।

Difference user को दिया गया PROMISE है:

  • एक switch एक ऐसी setting flip करता है जो immediately act करती है: reminders on, dark mode on: कोई Submit button नहीं follow करता
  • एक checkbox एक choice mark करता है जो form बाद में submit करेगा: carry bag, terms accepted

नीचे same bool; screen पर अलग social contract। उस contract से choose करना एक design mark है जो examiners genuinely award करते हैं।

Quiz

आपका syllabus Toast कहता है। Flutter में Toast के बारे में honest, exam-safe statement क्या है?

  1. Flutter एक Toast widget ship करता है: Toast.show(context, 'message')
  2. Flutter में कोई built-in Toast नहीं है: SnackBar native equivalent है, और Android-style toasts fluttertoast package से आते हैं
  3. Flutter में Toasts short duration वाले AlertDialogs हैं
  4. SnackBar और Toast एक ही built-in widget के 2 नाम हैं
Show the answer

Flutter में कोई built-in Toast नहीं है: SnackBar native equivalent है, और Android-style toasts fluttertoast package से आते हैं

Honest map में 3 landmarks हैं: कोई built-in Toast exist नहीं करता; SnackBar framework का अपना passing message है (bottom strip, auto-dismiss, optional action); और pub.dev PACKAGE fluttertoast उन students के लिए literal Android-style floating toasts supply करता है जो चाहते हैं। Option A एक API invent करता है: उन students के लिए trap जो assume करते हैं हर Android noun का Flutter twin है। Option C passive FYI को modal interrogation से confuse करता है: पिछले lesson ने exactly वह line draw की। Option D 2 distinct चीज़ों को merge करता है: एक widget है जो Flutter ship करता है, दूसरा एक concept जो यह deliberately नहीं ship करता।

Think first

Switch या Checkbox? 4 Rows पर Rule कीजिए

FestConnect Flutter की screens से चार rows: (a) Settings में Event reminders on/off, (b) registration form पर I agree to the fest rules, (c) Settings में Dark mode, (d) booking form पर Add a carry bag। PROMISE से switch या checkbox assign कीजिए, फिर tap कीजिए।

Show the answer

(a) और (c): switches: settings जो flip होते ही effect लेती हैं, कोई submission ceremony नहीं। (b) और (d): checkboxes: choices जिनका कोई मतलब नहीं जब तक form का Book/Register button उन्हें submit न करे। एक question में test: क्या इसे flip करना अभी act करता है, या यह किसी ऐसी चीज़ का हिस्सा है जो बाद में submitted होगी? Same bool, same setState: widget choice timing के बारे में एक message है, और उन्हें mix करना (form पर एक switch, settings में एक checkbox) हर platform पर चुपचाप users को confuse करता है।

Watch out

Passing-Message Slips

Snackbars Stack करना: कई fire करना उन्हें seconds के लिए queue करता है हर एक के लिए; current हटाने के बाद showSnackBar (hideCurrentSnackBar) news को fresh रखता है।

SnackBar में Vital Info: यह खुद dismiss होता है: जिस पर user को MUST act करना है वह एक dialog में belong करता है; जो उन्हें सिर्फ़ जानना है वह pass by कर सकता है।

UNDO जो Undo नहीं कर सकता: action offer करना आपको release implement करने के लिए oblige करता है: एक UNDO जो shrug करता है कुछ न होने से बुरा है।

Theory

Interruption Spectrum, Complete

अब आपके पास user से बात करने का पूरा Flutter spectrum है: Tooltip request पर whisper करता है, SnackBar passing में mention करता है, AlertDialog रुककर पूछता है: सिर्फ़ जितनी news demand करे उतना escalate कीजिए (BCA404 का ErrorProvider-vs-MsgBox judgement, आख़िरकार cross-platform)। पूरे subject में एक lesson बाकी है: charts और Form widget: FestConnect Flutter की registration, validated और finished।

Summary

Key takeaways

  • Flutter कोई Toast ship नहीं करता: यह कहिए; SnackBar native passing message है, fluttertoast package route है।
  • ScaffoldMessenger.of(context).showSnackBar(SnackBar(content, duration, action)): bottom strip, auto-dismiss।
  • SnackBarAction एक toast के पास कभी न रही one-tap UNDO देता है।
  • Switch: value + onChanged + setState: controlled law का चौथा witness; rows के लिए SwitchListTile।
  • Switch = setting जो NOW act करती है; checkbox = choice जो LATER submitted होती है: same bool, अलग promise।
  • Interruptions honestly escalate कीजिए: tooltip, snackbar, dialog।
  • Memory hook: snackbars pass by होते हैं, switches अभी act करते हैं, यहाँ कोई toast नहीं रहता।

Study this properly

This page is the lesson to read. In Gri-Learn the same topic is a graded deck: the self-checks are scored and your weak topics are tracked. Free to start.

Start this topic

Already have an account? Sign in

More from Flutter widget (Constructor, attributes and Properties)

Gri-Learn · syllabus-mapped B.C.A. lessons in English, Hindi and Gujarati

Toast, Switch · Mobile Application Development - 2 (option B) · Gri-Learn