0% found this document useful (0 votes)
3 views6 pages

Connexion

This document is a Flutter application code that creates a simple user interface with a form for user information input. It includes features such as a drawer for navigation, a bottom navigation bar, and a floating action button. The form collects user details like name, password, gender, and hobbies, and displays a confirmation dialog before submission.

Uploaded by

hindemelais
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Connexion

This document is a Flutter application code that creates a simple user interface with a form for user information input. It includes features such as a drawer for navigation, a bottom navigation bar, and a floating action button. The form collects user details like name, password, gender, and hobbies, and displays a confirmation dialog before submission.

Uploaded by

hindemelais
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

import 'package:flutter/material.

dart';

void main() {
runApp(const MyApp());
}

class MyApp extends StatelessWidget {


const MyApp({super.key});

// This widget is the root of your application.


@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: MyHomePage(),
);
}
}

class MyHomePage extends StatefulWidget {


const MyHomePage({super.key});

@override
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

int selectedIndex = 0;
final nameController = TextEditingController();
String? sexe;
bool music = false;
bool mangas = false;
bool football = false;
final formKey = GlobalKey<FormState>();
String name = "Jonh Doe";
bool loading = false;
bool displayInfo = false;

displayDialog(BuildContext context) {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text("Confirmation"),
content: Text("Etes-vous sur de vouloir soumettre ce formulaire ?"),
actions: [
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: Text("Annuler")
),
TextButton(
onPressed: () {
Navigator.pop(context);
setState(() {
loading = true;
});
Future.delayed(Duration(seconds: 5), () {
setState(() {
loading = false;
name = nameController.text;
displayInfo = true;
});
});
},
child: Text("Ok")
),
],
);
}
);
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.redAccent,
title: Text('Titre de la page', style: TextStyle(color: Colors.white),),
actions: [
IconButton(onPressed: null, icon: Icon(Icons.add_alert, color:
Colors.white)),
IconButton(onPressed: null, icon: Icon(Icons.search, color:
Colors.white))
],
),
drawer: Drawer(
child: ListView(
children: [
DrawerHeader(
child: Column(
children: [
CircleAvatar(
child: Text(name.substring(0, 2), style: TextStyle(fontSize:
40, color: Colors.white),),
radius: 50.0,
backgroundColor: Colors.black54,
),
Text(name, style: TextStyle(color: Colors.white, fontSize: 20),),
],
),
decoration: BoxDecoration(
color: Colors.redAccent
),
),
ListTile(
leading: Icon(Icons.message),
title: Text("Messages"),
),ListTile(
leading: Icon(Icons.person),
title: Text("Profile"),
),ListTile(
leading: Icon(Icons.settings),
title: Text("Paramètres"),
),
],
),
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: selectedIndex,
selectedItemColor: Colors.redAccent,
onTap: (int index) {
setState(() {
selectedIndex = index;
});
},
items: const<BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Inscription'
),
BottomNavigationBarItem(
icon: Icon(Icons.info),
label: 'Information'
),
BottomNavigationBarItem(
icon: Icon(Icons.settings),
label: 'Paramètres'
),
],
),
floatingActionButton: FloatingActionButton(
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Floating bouton cliqué"))
);
},
backgroundColor: Colors.redAccent,

child: Icon(Icons.add, color: Colors.white,),


),
body: Container(
padding: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
child: SingleChildScrollView(
child: Column(
children: [
Text("USER INFO", style: TextStyle(fontWeight: FontWeight.bold,
fontSize: 18, color: Colors.redAccent ),),
SizedBox(height: 15.0,),
Center(
child: Image.asset('assets/avatar.png', scale: 7,),
),
SizedBox(height: 15.0,),
Form(
key: formKey,
child: Column(
children: [
TextFormField(
keyboardType: TextInputType.name,
controller: nameController,
decoration: InputDecoration(
label: Text('Nom & Prénom(s)'),
hintText: 'Entrer votre nom et prénom',
icon: Icon(Icons.person)
),
validator: (String? value) {
return value == null || value == "" ? "Ce champ est
obligatoire" : null;
},
),
TextFormField(
keyboardType: TextInputType.text,
obscureText: true,
controller: null,
decoration: InputDecoration(
label: Text('Mot de passe'),
hintText: 'Définir votre mot de passe',
icon: Icon(Icons.lock)
),
validator: (String? value) {
return value == null || value == "" ? "Ce champ est
obligatoire" : null;
},
),
DropdownButtonFormField(
decoration: InputDecoration(
icon: Icon(Icons.transgender),
label: Text('Genre'),
hintText: "Sélectionner votre genre"
),
items: [
DropdownMenuItem(
child: Text('Masculin'),
value: 'Masculin',
),
DropdownMenuItem(
child: Text('Féminin'),
value: 'Féminin',
),
DropdownMenuItem(
child: Text('Autre'),
value: 'Autre',
),
],
onChanged: (String? value) {
setState(() {
sexe = value;
});
},
),
SizedBox(height: 15,),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Sélectionner vos passe temps", style:
TextStyle(fontSize: 17),),
SizedBox(height: 10,),
Row(
children: [
Checkbox(
value: football,
onChanged: (bool? b) {
setState(() {
football = b!;
});
}
),
Text("Football", style: TextStyle(fontSize: 16),)
],
),
Row(
children: [
Checkbox(
value: mangas,
onChanged: (bool? b) {
setState(() {
mangas = b!;
});
}
),
Text("Mangas", style: TextStyle(fontSize: 16),)
],
),
Row(
children: [
Checkbox(
value: music,
onChanged: (bool? b) {
setState(() {
music = b!;
});
}
),
Text("Musique", style: TextStyle(fontSize: 16),)
],
),

],
),
SizedBox(height: 10,),
ElevatedButton(
onPressed: () {
if(formKey.currentState!.validate()) {
displayDialog(context);
}
},
child: loading ? SizedBox(
height: 30,
width: 30,
child: CircularProgressIndicator(
strokeWidth: 2,
),
) : Text("Valider")
)
],
)
)
],
),
),
),
);
}
}

You might also like