Reforzar el uso de objetos para comprender el paradigma de la programación orientada a objetos en el cómputo móvil.
En este tema conocerás un breve tratado de la programación orientada a objetos con un enfoque en el paradigma de cómputo móvil. Te servirá como una revisión de los fundamentos ajustados al entorno de desarrollo de Flutter. También abordarás el concepto de estado y cuál es su función dentro del desarrollo de aplicaciones móviles.
Los siguientes enlaces son externos a la Universidad Tecmilenio, al acceder a ellos considera que debes apegarte a sus términos y condiciones.
Navegar entre escenas mediante los botones situados en la parte inferior de la pantalla.
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: _ currentPage,
),
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.cake),
title: Text('Birthdays'),
),
BottomNavigationBarItem(
icon: Icon(Icons.sentiment_satisfied),
title: Text('Gratitude'),
),
BottomNavigationBarItem(
icon: Icon(Icons.access_alarm),
title: Text('Reminders'),
),
],
onTap: (selectedIndex) => _changePage(selectedIndex),
),
void _changePage(int selectedIndex) {
setState(() {
_currentIndex = selectedIndex;
_currentPage = _listPages[selectedIndex];
});
}
Es importante que sepas que el widget _currentPage muestra cada ruta sin necesidad de usar el Navigator widget.
En la primera línea, después de _HomeState, se definen las siguientes variables:
int _currentIndex = 0;
List _listPages = List();
Widget _currentPage;
@override
void initState() {
super.initState();
_listPages
..add(Birthdays())
..add(Gratitude())
..add(Reminders());
_currentPage = Birthdays();
}
// birthdays.dart
import 'package:flutter/material.dart';
class Birthdays extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Icon(
Icons.cake,
size: 120.0,
color: Colors.orange,
),
),
);
}
}
// gratitude.dart
import 'package:flutter/material.dart';
class Gratitude extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Icon(
Icons.sentiment_satisfied,
size: 120.0,
color: Colors.lightGreen,
),
),
);
}
}
// reminders.dart
import 'package:flutter/material.dart';
class Reminders extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Icon(
cons.access_alarm,
size: 120.0,
color: Colors.purple,
),
),
);
}
import 'package:flutter/material.dart';
import 'gratitude.dart';
import 'reminders.dart';
import 'birthdays.dart';
class Home extends StatefulWidget {
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
int _currentIndex = 0;
List _listPages = List();
Widget _currentPage;
@override
void initState() {
super.initState();
_listPages
..add(Birthdays())
..add(Gratitude())
..add(Reminders());
_currentPage = Birthdays();
}
void _changePage(int selectedIndex) {
setState(() {
_currentIndex = selectedIndex;
_currentPage = _listPages[selectedIndex];
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('BottomNavigationBar'),
),
body: SafeArea(
child: Padding(
padding: EdgeInsets.all(16.0),
child: _currentPage,
),
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.cake),
title: Text('Birthdays'),
),
BottomNavigationBarItem(
icon: Icon(Icons.sentiment_satisfied),
title: Text('Gratitude'),
),
BottomNavigationBarItem(
icon: Icon(Icons.access_alarm),
title: Text('Reminders'),
),
],
onTap: (selectedIndex) => _changePage(selectedIndex),
),
);
}
}