Nggunakake RawDialogRoute ing Flutter: Pandhuan lan Conto

RawDialogRoute iku kelas ing Flutter sing nggantosi rute dialog mentahan, nyediakake cara kanggo nampilake dialog adat utawa popups. Kelas iki biasane digunakake sacara internal dening kerangka kanggo nggawe lan ngatur rute dialog.

Iki conto carane sampeyan bisa nggunakake RawDialogRoute kanggo nampilake dialog khusus:

import 'package:flutter/material.dart';  
  
void main() {  
  runApp(MyApp());  
}  
  
class MyApp extends StatelessWidget {  
  @override  
  Widget build(BuildContext context) {  
    return MaterialApp(  
      home: MyHomePage(),  
   );  
  }  
}  
  
class MyHomePage extends StatelessWidget {  
  @override  
  Widget build(BuildContext context) {  
    return Scaffold(  
      appBar: AppBar(  
        title: Text('RawDialogRoute Example'),  
     ),  
      body: Center(  
        child: ElevatedButton(  
          onPressed:() {  
            showDialog(  
              context: context,  
              builder:(BuildContext context) {  
                return RawDialogRoute(  
                  context: context,  
                  barrierDismissible: true,  
                  builder:(BuildContext context) {  
                    return AlertDialog(  
                      title: Text('Custom Dialog'),  
                      content: Text('This is a custom dialog using RawDialogRoute.'),  
                      actions: [  
                        TextButton(  
                          onPressed:() {  
                            Navigator.pop(context);  
                          },  
                          child: Text('Close'),  
                       ),  
                      ],  
                   );  
                  },  
               );  
              },  
           );  
          },  
          child: Text('Open Dialog'),  
       ),  
     ),  
   );  
  }  
}  

Ing conto iki, nalika tombol dipencet, fungsi showDialog digunakake kanggo nampilake dialog adat nggunakake RawDialogRoute minangka builder. Ing njero builder, sampeyan bisa nyedhiyakake konten khusus kanggo dialog kasebut.

Wigati dimangerteni manawa bisa uga dianggep minangka kelas tingkat rendah, lan sampeyan bisa uga luwih trep nggunakake kelas utawa kelas RawDialogRoute sing dibangun kanggo nggawe dialog ing pirang-pirang kasus. AlertDialog SimpleDialog