How can I get the Navigator to work in Flutter? - android

I'm new on Flutter, so obviously I'm messing up somewhere in the code that I'm not being able to figure out. Basically I have a login screen from which I want to navigate to a second screen, but when I select the button absolutely nothing happens, nor does an error appear. I have been looking all over for an answer but none of them can solve the problem. I hope someone can help me. (The texts of the buttons are in Spanish).
This is the main.dart:
import 'package:flutter/material.dart';
import 'package:go_out/screens/screens.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
initialRoute: 'home',
routes: {
'home': (_) => const HomeScreen(),
'signInEmail': (_) => const SignInEmail(),
},
);
}
}
This is the home_screen.dart:
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import '../widgets/widgets.dart';
class HomeScreen extends StatelessWidget {
const HomeScreen({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return const Scaffold(
backgroundColor: Colors.black,
body: Padding(
padding: EdgeInsets.only(left: 15, right: 15),
child: Center(
child: _SignInPageDesign(),
),
),
);
}
}
class _SignInPageDesign extends StatelessWidget {
const _SignInPageDesign({
Key? key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(left: 10, right: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
'images/logo.png',
height: 200,
fit: BoxFit.cover,
),
const SizedBox(
height: 30,
),
CustomElevatedButtonWithoutIcon(
text: 'Crear Cuenta',
onPressed: () => Navigator.pushNamed(context, 'signInEmail'),
),
const SizedBox(height: 12),
CustomElevatedButtonWithIcon(
text: 'Continuar con Facebook',
onPressed: () {},
icon: FontAwesomeIcons.facebookSquare,
),
const SizedBox(height: 12),
CustomElevatedButtonWithIcon(
text: 'Continuar con Google',
onPressed: () {},
icon: FontAwesomeIcons.google,
),
const SizedBox(height: 12),
CustomElevatedButtonWithIcon(
text: 'Continuar con Apple',
onPressed: () {},
icon: FontAwesomeIcons.apple,
),
const SizedBox(height: 12),
const CustomTextButton(
text: 'Iniciar sesión',
),
const SizedBox(height: 12),
CustomElevatedButtonWithoutIcon(
text: 'Registrar comercio',
onPressed: () {},
),
],
),
);
}
}
This is the problem with home_screen.dart which does not return any value.
CustomElevatedButtonWithoutIcon(
text: 'Crear Cuenta',
onPressed: () => Navigator.pushNamed(context, 'signInEmail'),
),
This is the second screen I want to go to sign_in_email.dart:
import 'package:flutter/material.dart';
class SignInEmail extends StatelessWidget {
const SignInEmail({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: const Color.fromRGBO(254, 80, 0, 1),
),
);
}
}
This is the class CustomElevatedButtonWithoutIcon:
import 'package:flutter/material.dart';
class CustomElevatedButtonWithoutIcon extends StatelessWidget {
const CustomElevatedButtonWithoutIcon({
Key? key,
required this.text,
required this.onPressed,
}) : super(key: key);
final String text;
final VoidCallback onPressed;
#override
Widget build(BuildContext context) {
return ElevatedButton(
child: Text(
text,
style:
const TextStyle(color: Colors.black, fontWeight: FontWeight.bold),
),
onPressed: () {},
style: ButtonStyle(
fixedSize: MaterialStateProperty.all<Size>(const Size(0, 50)),
backgroundColor: MaterialStateProperty.all<Color>(
const Color.fromRGBO(254, 80, 0, 1)),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
),
),
);
}
}

You didn't pass anything onPressed funciton, you kept it empty, so nothing was working, just pass your onPressed function inside ElevatedButton like below
import 'package:flutter/material.dart';
class CustomElevatedButtonWithoutIcon extends StatelessWidget {
const CustomElevatedButtonWithoutIcon({
Key? key,
required this.text,
required this.onPressed,
}) : super(key: key);
final String text;
final VoidCallback onPressed;
#override
Widget build(BuildContext context) {
return ElevatedButton(
child: Text(
text,
style:
const TextStyle(color: Colors.black, fontWeight: FontWeight.bold),
),
onPressed: onPressed,
style: ButtonStyle(
fixedSize: MaterialStateProperty.all<Size>(const Size(0, 50)),
backgroundColor: MaterialStateProperty.all<Color>(
const Color.fromRGBO(254, 80, 0, 1)),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
),
),
);
}
}
Also it's best practice to use RouteGenerator, create a route_generator.dart file with the following code below
import 'package:flutter/material.dart';
class RouterCustom {
static Route<dynamic> generateRoute(RouteSettings settings) {
final args = settings.arguments;
switch (settings.name) {
case "home":
return MaterialPageRoute(
builder: (_) => const HomeScreen(),
settings: const RouteSettings(name: "home"),
);
case "signInEmail":
return MaterialPageRoute(
builder: (_) => const SignInEmail(),
settings: const RouteSettings(name: "signInEmail"),
);
default:
return MaterialPageRoute(
builder: (_) => Scaffold(
body: Center(
child: Text('No route defined for ${settings.name}'),
),
),
settings: const RouteSettings(name: "404"),
);
}
}
}
Then pass it to your main method's router param
MaterialApp(
initialRoute: "home",
onGenerateRoute: RouterCustom.generateRoute,
)

CustomElevatedButtonWithoutIcon doesn't actually do anything when pressed, onPressed: () {}, should be onPressed: onPressed,.
A simple way to detect this, is by adding a print statement right before navigating, or adding a breakpoint. If neither is triggered, the function isn't being called and your issue isn't in the Navigation.

Your widget CustomElevatedButtonWithoutIcon is not calling any function after it is being pressed
You have this
onPressed: () {},
Change it for
onPressed: onPressed

Related

How to refer multiple values sepererately in flutter firebase?

import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_auth/firebase_auth.dart';
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: Authentication (),
);
}
}
class Authentication extends StatelessWidget {
const Authentication({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return StreamBuilder(
stream: FirebaseAuth.instance.authStateChanges(),
builder: (context, snapshot){
if(!snapshot.hasData){
return const SignInScreen(
providerConfigs: [
EmailProviderConfiguration()
],
);
}
return const Diarymain ();
},
);
}
}
class Diarymain extends StatefulWidget {
const Diarymain({Key? key}) : super(key: key);
#override
State<Diarymain> createState() => _DiarymainState();
}
class _DiarymainState extends State<Diarymain> {
final fbs = FirebaseDatabase.instance;
var currentUser = FirebaseAuth.instance.currentUser;
#override
Widget build(BuildContext context) {
final ref = fbs.ref().child('diary').child(currentUser!.uid);
return Scaffold(
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.grey[350],
onPressed: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (_) => AddEditDiary(),
),
);
},
child: const Icon(
Icons.add,
),
),
appBar: AppBar(title: Text('Diary'),),
body: FirebaseAnimatedList(
query: ref,
shrinkWrap: true,
itemBuilder: (context, snapshot, animation, index) {
return GestureDetector(
onTap: () {},
child: Container(
child: Padding(
padding: const EdgeInsets.all(8.0),
// child: ListView.builder(
// itemBuilder: (context, index) {
child: ListTile(
shape: RoundedRectangleBorder(
side: const BorderSide(
color: Colors.white,
),
borderRadius: BorderRadius.circular(10),
),
tileColor: Colors.blue[50],
trailing: IconButton(
icon: Icon(
Icons.delete,
color: Colors.blueGrey[900],
),
onPressed: () {
ref.child(snapshot.key!).remove();
},
),
title: Text(
snapshot.value.toString(),
style: const TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
),
),
),
// },)
),
),
);
},
),
);
}
}
class AddEditDiary extends StatefulWidget {
const AddEditDiary({Key? key}) : super(key: key);
#override
State<AddEditDiary> createState() => _AddEditDiaryState();
}
class _AddEditDiaryState extends State<AddEditDiary> {
TextEditingController title = TextEditingController();
TextEditingController subtitle = TextEditingController();
final fbs = FirebaseDatabase.instance;
var currentUser = FirebaseAuth.instance.currentUser;
#override
Widget build(BuildContext context) {
final ref = fbs.ref().child('diary').child(currentUser!.uid);
return Scaffold(
appBar: AppBar(title: Text('Add'),),
body: ListView(
children: <Widget> [
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
controller: title,
decoration: InputDecoration(
labelText: 'Title',
hintText: 'Enter Title',
border: OutlineInputBorder(),
),
)
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
controller: subtitle,
decoration: InputDecoration(
labelText: 'Subtitle',
hintText: 'Enter Subtitle',
border: OutlineInputBorder(),
),
)
),
Padding(
padding: const EdgeInsets.all(8.0),
child: RaisedButton(
onPressed: () {
ref
.push()
.set({
'title' : title.text,
'subtitle' : subtitle.text,
})
.asStream();
Navigator.pushReplacement(
context, MaterialPageRoute(builder: (_) => Diarymain()));
},
child: Text('Save', style: TextStyle(color: Colors.white),),
color: Colors.pink,
),
)
]
)
);
}
}
I'm trying to make a diary and two things which are title and subtitle are stored in the firebase real-time database. Below part of code shows how they are added in the firebase.
child: RaisedButton(
onPressed: () {
ref
.push()
.set({
'title' : title.text,
'subtitle' : subtitle.text,
})
.asStream();
When title and subtitles are shown on the page, I want to show them separately and I think I need something value to refer them individually.
In my code, "snapshot.value.toString()," shows only both title and subtitle together.
Is there any way to indicate them separately?
I would appreciate it if anyone can help me with this.

Encaplsulating a widget for use in another dart file

What I'm trying to achieve:
Have a BottomNavigationBar widget in its own class in its own dart file called navigationBar.dart
Have a main.dart file that has a Scaffold widget that calls this class to create the BottomNavigationBar widget
Then in the main.dart file I want to be able to set the BottomNavigationBar from navigationBar.dart and I want to be able to change the body of the Scaffold widget in the main.dart file depending on which index is selected in the BottomNavigationBar widget (check the comment in the main.dart file in the body property for a better explanation)
Here is my code below so far:
navigationBar.dart
import 'package:flutter/material.dart';
import '../home.dart';
class NavigationBar extends StatefulWidget {
const NavigationBar({Key? key}) : super(key: key);
#override
State<NavigationBar> createState() => _NavigationBar();
}
class _NavigationBar extends State<NavigationBar> {
int selectedIndex = 2;
void _onItemTapped(int index) {
setState(() {
selectedIndex = index;
});
}
#override
Widget build(BuildContext context) {
return BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
backgroundColor: Colors.red,
),
BottomNavigationBarItem(
icon: Icon(Icons.business),
label: 'Business',
backgroundColor: Colors.green,
),
BottomNavigationBarItem(
icon: Icon(Icons.school),
label: 'School',
backgroundColor: Colors.purple,
),
BottomNavigationBarItem(
icon: Icon(Icons.settings),
label: 'Settings',
backgroundColor: Colors.pink,
),
],
currentIndex: selectedIndex,
selectedItemColor: Colors.amber[800],
onTap: _onItemTapped,
);
}
main.dart
import 'package:flutter/material.dart';
import 'components/navigationBar.dart';
void main() {
runApp(const MaterialApp(home: App()));
}
class App extends StatefulWidget {
const App({Key? key}) : super(key: key);
#override
State<App> createState() => _App();
}
class _App extends State<App> {
static const List<Widget> _widgetOptions = <Widget>[
Text(
'Index 0: Home',
),
Text(
'Index 1: Business',
),
Text(
'Index 2: School',
),
Text(
'Index 3: Settings',
),
];
#override
Widget build(BuildContext context) {
const navBar = navigationBar()
return Scaffold(
appBar: AppBar(
title: const Text('Test App',
style: TextStyle(
color: Colors.white,
fontFamily: 'LogoFont',
fontSize: 30.0,
letterSpacing: 1.5)),
centerTitle: true,
backgroundColor: Colors.lightBlue[500],
elevation: 0.0,
),
backgroundColor: Colors.lightBlue[800],
body: //something like this: _widgetOptions.elementAt(navbar.selectedIndex)
),
bottomNavigationBar: navBar);
}
}
Any ideas on how I could create what I need in the bullet points? Any help would be great, thanks
I think there is no way with stateful widget but you can do this by provider, like example below.
Provider:
class MainViewProvider with ChangeNotifier ,
DiagnosticableTreeMixin{
int activeItem = 2;
changeActiveItem(int activeElement){
activeItem = activeElement;
notifyListeners();
}
}
BottomNavBar Widget:
class BotNavWidget extends StatelessWidget {
const BotNavWidget({Key? key}) : super(key: key);
get context => null;
#override
Widget build(BuildContext context) {
final watch = context.watch<ColorsProvider>();
return Container(
padding: EdgeInsets.symmetric(
horizontal: getWidth(16), vertical: getHeight(10)),
child: Container(
height: SizeConfig.height! * .1,
width: SizeConfig.width!,
decoration: BoxDecoration(
color: watch.colors[1],
borderRadius: BorderRadius.circular(getWidth(20))),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
buildIcon(watch.bottomIcons[0], context, 0),
buildIcon(watch.bottomIcons[1], context, 1),
buildIcon(watch.bottomIcons[2], context, 2),
buildIcon(watch.bottomIcons[3], context, 3),
buildIcon(watch.bottomIcons[4], context, 4),
],
),
),
);
}
buildIcon(ColorFiltered icon, BuildContext context, int i) {
final read = context.read<MainViewProvider>();
final watch = context.watch<MainViewProvider>();
final watchColors = context.watch<ColorsProvider>().colors;
return InkWell(
onTap: () async{
read.changeActiveItem(i);
},
child: Container(
padding: EdgeInsets.all(getWidth(15)),
height: SizeConfig.height! * .07,
width: SizeConfig.height! * .07,
decoration: BoxDecoration(
color: watch.activeItem == i ? watchColors[2] : Colors.transparent,
borderRadius: BorderRadius.circular(getWidth(20))),
child: SizedBox(
height: getHeight(24),
width: getHeight(24),
child: icon
),
),
);
}
}
P.S: You can use custom BottomNavigationBar Widget instead of making it manually

onPressed from MaterialButton were trigged when the page from initialRoute

There're two buttons from my WelcomeScreen, when this page is loaded, two buttons will be pressed automatically.
two buttons were used by the external widget"RoundButton".
Why I knew those buttons were being pressed, because I was using print function, and I saw the first button and second button were pressed automatically and sequentially.
Navigator.pushNamed(context, LoginScreen2.id);
Navigator.pushNamed(context, RegistrationScreen.id);
Navigator.pushNamed(context, LoginScreen2.id);
Navigator.pushNamed(context, RegistrationScreen.id);
Is there any setting I should set to prevent this problem? Thank you.
environment:
sdk: ">=2.16.0 <3.0.0"
build this program on Chroma
welcome_screen.dart
import 'package:trashcollectionday/Screens/login_screen2.dart';
import 'package:trashcollectionday/screens/registration_screen.dart';
import 'package:flutter/material.dart';
import 'package:trashcollectionday/screens/login_screen.dart';
import 'package:animated_text_kit/animated_text_kit.dart';
import 'package:trashcollectionday/components/roundedButton.dart';
class WelcomeScreen extends StatefulWidget {
static const String id = 'welcome_screen';
// will be a class, you don't have to to WelcomeScreen().index
#override
_WelcomeScreenState createState() => _WelcomeScreenState();
}
class _WelcomeScreenState extends State<WelcomeScreen> with SingleTickerProviderStateMixin {
late AnimationController controller;
late Animation animation;
late Animation animation1;
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey,
body: Padding(
padding: EdgeInsets.symmetric(horizontal: 24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Row(
children: <Widget>[
Hero(
tag: 'logo',
child: Container(
child: Image.asset('images/logo.png'),
height: 60,
),
),
DefaultTextStyle(
style: const TextStyle(
fontSize: 40.0,
fontFamily: 'Horizon',
),
child: AnimatedTextKit(
animatedTexts: [TypewriterAnimatedText('Application')],
),
),
],
),
const SizedBox(
height: 48.0,
),
RoundButton(
title: 'Log In',
colour: Colors.lightBlue,
onPressed: () {
print('Log In');
//Go to login screen.
Navigator.pushNamed(context, LoginScreen2.id);
},
),
RoundButton(
title: 'Register',
colour: Colors.blueAccent,
onPressed: () {
print('Reg');
//Go to login screen.
Navigator.pushNamed(context, RegistrationScreen.id);
},
),
],
),
),
);
}
}
roundedButton.dart
import 'package:flutter/material.dart';
class RoundButton extends StatelessWidget {
const RoundButton({required this.title, required this.colour, required this.onPressed});
final Color colour;
final String title;
final Function onPressed;
#override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: Material(
elevation: 5.0,
color: colour,
borderRadius: BorderRadius.circular(30.0),
child: MaterialButton(
onPressed: onPressed(),
minWidth: 200.0,
height: 42.0,
child: Text(
title,
),
),
),
);
}
}
main. dart
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: Colors.teal,
textTheme: const TextTheme(bodyText2: TextStyle(color: Colors.yellow)),
primaryColor: Colors.orange,
),
initialRoute: WelcomeScreen.id,
// home: ItemDetailsScrrent(),
routes: {
WelcomeScreen.id : (context) => WelcomeScreen(),
LoginScreen2.id: (context) => LoginScreen2(),
RegistrationScreen.id: (context) => RegistrationScreen(),
RecordScreen.id: (context) => RecordScreen(),
LoginScreen.id: (context) => LoginScreen(),
ItemDetailsScrrent.id: (context) => ItemDetailsScrrent(),
},
// home: const LoginScreen(),
);
}
}
You should remove brackets from RoundButton class in
onPressed: onPressed()
to
onPressed:onPressed
and add brackets to this line of code
final Function onPressed;
as here
final Function() onPressed;
I'm not sure but maybe issue occurs because of you are using onPressed: onPressed() in RoundButton.
You can use this function without brackets like this; onPressed: onPressed,

How to open this type of alert dialog in flutter

I wanted to show dialog in my application. How can i achieve this using flutter
You can use a PopupMenuButton (https://api.flutter.dev/flutter/material/PopupMenuButton-class.html) to achieve this in flutter.
See example code below:
PopupMenuButton<int>(
itemBuilder: (context) => [
const PopupMenuItem(
value: 1,
child: Center(
child: Icon(
Icons.download_outlined,
size: 30.0,
),
),
),
const PopupMenuItem(
value: 2,
child: Center(
child: Icon(
Icons.link,
size: 30.0,
),
),
),
const PopupMenuItem(
value: 2,
child: Center(
child: Icon(
Icons.share,
size: 30.0,
),
),
),
],
icon: const Icon(
Icons.more_horiz,
size: 40.0,
),
offset: const Offset(150, -150),
);
The above example popups a list of Icons when the PopupMenuButton is pressed.
You can adapt this to your use-case above.
Finally I found a Solution thanks enfinity. Here how i solve the problem.
import 'package:flutter/material.dart';
void main() {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
home: new MyHomePage(),
);
}
}
/// An arbitrary widget that lives in a popup menu
class PopupMenuWidget<T> extends PopupMenuEntry<T> {
const PopupMenuWidget({ Key key, this.height, this.child }) : super(key: key);
#override
final Widget child;
#override
final double height;
#override
bool get enabled => false;
#override
_PopupMenuWidgetState createState() => new _PopupMenuWidgetState();
}
class _PopupMenuWidgetState extends State<PopupMenuWidget> {
#override
Widget build(BuildContext context) => widget.child;
}
class MyHomePage extends StatelessWidget {
MyHomePage({Key key}) : super(key: key);
#override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
actions: <Widget>[
new PopupMenuButton<String>(
onSelected: (String value) {
print("You selected $value");
},
itemBuilder: (BuildContext context) {
return [
new PopupMenuWidget(
height: 40.0,
child: new Row(
children: [
IconButton(
icon: Icon(
Icons.remove,
color: Colors.green,
),
onPressed: () {
print("Remove");
}),
Text("1"),
IconButton(
icon: Icon(
Icons.add,
color: Colors.green,
),
onPressed: () {
print("Add");
}),
],
),
),
];
}
),
],
),
);
}
}

Black-Screen with the FlatButton in the AppBar

My App contains basically 2 parts -> Appbar (with 1 Button) and BottomNavigationBar (with some buttons that works properly). The problem came when I pressed the Appbar button (goes to a black screen instead of show the "manual_page.dart")
this is the content of the 2 files (the home_page.dart and manual_page.dart):
home_page.dart
import 'package:flutter/material.dart';
import 'package:opening_a_pdf/manual_page.dart';
import 'package:opening_a_pdf/first_page.dart';
import 'package:opening_a_pdf/second_page.dart';
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _selectedPage = 0;
List<Widget> pageList = List<Widget>();
#override
void initState() {
pageList.add(FirstPage());
pageList.add(SecondPage());
super.initState();
}
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xFFFAFAFA),
appBar: AppBar(
backgroundColor: Colors.black,
title: const Text('Aplicación en Desarrollo'),
actions: <Widget>[
FlatButton(
textColor: Colors.white,
child: Text(
'MANUAL',
style: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
),
),
onPressed: (){
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Voice()),
);
}
)
],
),
body: IndexedStack(
index: _selectedPage,
children: pageList,
),
bottomNavigationBar: BottomNavigationBar(
// type: BottomNavigationBarType.fixed,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
backgroundColor: Colors.black,
icon: Icon(Icons.compare_arrows),
title: Text('Conectividad'),
),
BottomNavigationBarItem(
backgroundColor: Colors.black,
icon: Icon(Icons.blur_on),
title: Text('Captura Datos'),
),
BottomNavigationBarItem(
backgroundColor: Colors.black,
icon: Icon(Icons.graphic_eq),
title: Text('Voz'),
),
BottomNavigationBarItem(
backgroundColor: Colors.black,
icon: Icon(Icons.list),
title: Text('Comandos'),
),
BottomNavigationBarItem(
backgroundColor: Colors.black,
icon: Icon(Icons.settings),
title: Text('Ajustes'),
),
],
currentIndex: _selectedPage,
selectedItemColor: Colors.amber[800],
onTap: _onItemTapped,
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
void _onItemTapped(int index) {
setState(() {
_selectedPage = index;
});
}
}
manual_page.dart
import 'package:flutter/material.dart';
// ignore: camel_case_types
class Voice extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Sección de Órdenes por Voz"),
),
body: Stack(
fit: StackFit.expand,
children: <Widget>[
Positioned(
bottom: 0,
width: MediaQuery.of(context).size.width,
child: Center(
child: MaterialButton(
onPressed: () {},
color: Colors.red,
),
),
)
],
),
);
}
}
Try to initial the height of container in the second screen before Stack
There are no errors in the code. Works correctly. Maybe the fault is in the main () or in the emulator.
Code in main:
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
I executed your code and found no problem with it:
But you can put empty Container() as the child of MaterialButton().
Corrected code:
MaterialButton(
onPressed: () {},
color: Colors.red,
child:Container(),
),

Categories

Resources