Flutter - navigation with BottomNavigationBar - flutter

In my application, I have the "Homepage" with BottomNavigationBar already installed and running with 4 different pages. After I access the "Perfil" screen and advance to other child screens (PaymentForm) and try to go back to the "Perfil" page, the BottomNavigationBar is not there. How do I return to the "HomePage" with the index corresponding to that screen "Perfil"? Codes below.
Homepage() with BottomNavigationBar:
class HomePage extends StatefulWidget {
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int _currentIndex = 0;
final tabs = [
Center(child: MainPage()),
Center(child: Text('Busca')),
Center(child: Text('Pedidos')),
Center(child: Perfil()),
];
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: tabs[_currentIndex],
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
type: BottomNavigationBarType.fixed,
items: [
BottomNavigationBarItem(
icon: Image.asset(
'assets/images/home_icone.png',
width: 40,
height: 40,
),
title: Text(
'Inicio',
style: TextStyle(color: Color(0xff203760)),
),
),
BottomNavigationBarItem(
icon: Image.asset(
'assets/images/busca_icone.png',
width: 40,
height: 40,
),
title: Text(
'Busca',
style: TextStyle(color: Color(0xff203760)),
),
),
BottomNavigationBarItem(
icon: Image.asset(
'assets/images/pedidos_icone.png',
width: 40,
height: 40,
),
title: Text(
'Pedidos',
style: TextStyle(color: Color(0xff203760)),
),
),
BottomNavigationBarItem(
icon: Image.asset(
'assets/images/perfil_icone.png',
width: 40,
height: 40,
),
title: Text(
'Perfil',
style: TextStyle(color: Color(0xff203760)),
),
),
],
onTap: (index) {
setState(() {
_currentIndex = index;
});
},
),
),
);
}
}
Perfil():
class Perfil extends StatefulWidget {
#override
_PerfilState createState() => _PerfilState();
}
class _PerfilState extends State<Perfil>{
final AuthService _auth = AuthService();
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.blueGrey,
width: 1.0,
),
),
),
height: 120,
width: double.maxFinite,
margin: EdgeInsets.fromLTRB(0, 20, 0, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Image.asset(
'assets/images/perfil_foto.png',
height: 60,
width: 60,
),
Text(
'$nameUser',
style: TextStyle(color: Color(0xff203760), fontSize: 28.0),
textAlign: TextAlign.center,
),
Image.asset(
'assets/images/right_arrow.png',
height: 40,
width: 40,
)
],
),
),
Padding(
padding: const EdgeInsets.all(5),
child: Column(
children: <Widget>[
ListView(
shrinkWrap: true,
children: <Widget>[
ListTile(
leading: Icon(
Icons.notifications_none,
size: 40.0,
color: Color(0xff203760),
),
title: Text(
"Notificações",
style: TextStyle(color: Color(0xff203760), fontSize: 20.0),
),
subtitle: Text(
"Central de notificações",
style: TextStyle(color: Color(0xff203760), fontSize: 16.0),
),
onTap: () {},
),
ListTile(
leading: Icon(
Icons.favorite_border,
size: 40.0,
color: Color(0xff203760),
),
title: Text(
"Favoritos",
style: TextStyle(color: Color(0xff203760), fontSize: 20.0),
),
subtitle: Text(
"Central de notificações",
style: TextStyle(color: Color(0xff203760), fontSize: 16.0),
),
onTap: () {},
),
ListTile(
leading: Icon(
Icons.payment,
size: 40.0,
color: Color(0xff203760),
),
title: Text(
"Formas de Pagamento",
style: TextStyle(color: Color(0xff203760), fontSize: 20.0),
),
subtitle: Text(
"Central de notificações",
style: TextStyle(color: Color(0xff203760), fontSize: 16.0),
),
onTap: () {
Navigator.of(context).push(MaterialPageRoute(builder: (context) => PaymentForm()));
},
),
ListTile(
leading: Icon(
Icons.location_on,
size: 40.0,
color: Color(0xff203760),
),
title: Text(
"Endereços",
style: TextStyle(color: Color(0xff203760), fontSize: 20.0),
),
subtitle: Text(
"Central de notificações",
style: TextStyle(color: Color(0xff203760), fontSize: 16.0),
),
onTap: () {},
),
ListTile(
leading: Image.asset(
'assets/images/logout.png',
width: 40,
height: 40,
),
title: Text(
"Sair",
style: TextStyle(color: Color(0xff203760), fontSize: 20.0),
),
subtitle: Text(
"Finalizar sessão",
style: TextStyle(color: Color(0xff203760), fontSize: 16.0),
),
onTap: () async {
await _auth.signOut();
},
),
],
),
],
),
)
],
),
),
),
);
}
}
PaymentForm() (child page from Perfil):
class PaymentForm extends StatefulWidget {
#override
_PaymentFormState createState() => _PaymentFormState();
}
class _PaymentFormState extends State<PaymentForm> {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Column(
children: <Widget>[
Container(
height: 120,
width: double.maxFinite,
margin: EdgeInsets.all(0),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.blueGrey,
width: 0.5,
),
),
),
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 25, 0, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
padding: const EdgeInsets.fromLTRB(15, 15, 10, 15),
child: ClipOval(
child: Container(
width: 35,
height: 35,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/left_arrow.png'),
),
),
child: FlatButton(
padding: EdgeInsets.all(0.0),
onPressed: () {
print('teste');
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HomePage()),
);
},
child: null,
),
),
),
),
Text(
" Formas de pagamento",
style:
TextStyle(color: Color(0xff203760), fontSize: 28.0),
textAlign: TextAlign.center,
),
],
),
),
),
Padding(
padding: const EdgeInsets.all(0),
child: Column(
children: <Widget>[
ListView(
shrinkWrap: true,
children: ListTile.divideTiles(
context: context,
color: Color(0xff203760),
tiles: [
ListTile(
title: Text(
"Cartão de crédito",
style: TextStyle(
color: Color(0xff203760), fontSize: 24.0),
),
subtitle: Text(
"Master ****** 3284",
style: TextStyle(
color: Color(0xff203760), fontSize: 12.0),
),
trailing: Image.asset(
'assets/images/menu_dots.png',
width: 10,
),
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => CartManager()));
},
),
],
).toList(),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
padding: const EdgeInsets.all(15),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Cartão de crédito",
style: TextStyle(
color: Color(0xff203760),
fontSize: 28.0,
),
),
],
),
),
Container(
padding: const EdgeInsets.all(15),
child: ClipOval(
child: Container(
width: 40,
height: 40,
decoration: BoxDecoration(
image: DecorationImage(
image:
AssetImage('assets/images/add_button.png'),
),
),
child: FlatButton(
padding: EdgeInsets.all(0.0),
onPressed: () {
print('teste');
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CartAdd()),
);
},
child: null,
),
),
),
),
],
),
],
),
)
],
),
),
);
}
}
Thanks for the help!!!

Your issue is that you are using the MaterialApp widget in each class. You don't need to do this. Only your HomePage needs to have it. On the other classes, you only need to have the content you want to show. Taking your code, removing the MaterialApp widgets and simplifying it without the parts you haven't shared, will make it work:
class HomePage extends StatefulWidget {
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int _currentIndex = 0;
final tabs = [
Center(child: Text('Main')),
Center(child: Text('Busca')),
Center(child: Text('Pedidos')),
Center(child: Text('Perfil')),
];
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: tabs[_currentIndex],
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
type: BottomNavigationBarType.fixed,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text(
'Inicio',
style: TextStyle(color: Color(0xff203760)),
),
),
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text(
'Busca',
style: TextStyle(color: Color(0xff203760)),
),
),
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text(
'Pedidos',
style: TextStyle(color: Color(0xff203760)),
),
),
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text(
'Perfil',
style: TextStyle(color: Color(0xff203760)),
),
),
],
onTap: (index) {
setState(() {
_currentIndex = index;
});
},
),
),
);
}
}

Related

Flutter: I would like to scroll the ListView after the main SingleChildScrollView Scroll end

I have a ListView.builder wrapped with a SingleChildScrollView, and each has its scroll, so when I click at the ListView it only scroll the ListView without Scroll the SingleChildScrollView, and my ListView is dynamic so I can't use physics: const NeverScrollableScrollPhysics() because it disable my ListVeiw.builder
I want to Scroll the main screen which has some widgets and the ListView, builder in the middle and in last has a bottom
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"Carrinho",
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 18,
fontFamily: 'Inter'),
),
),
body: SingleChildScrollView(
child: Column(
children: [
Stack(
children: <Widget>[
Container(
width: 400,
child: Image.asset('assets/images/cover.jpg'),
),
Center(
child: Column(
children: [
SizedBox(height: 60),
Text(
"MEU CESTO",
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 30,
fontFamily: 'Inter'),
),
],
),
),
],
),
Container(
height: 80,
padding: const EdgeInsets.all(15),
decoration: BoxDecoration(
color: sGreenColour,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10),
),
),
child: Container(
child: Column(
children: [
Row(children: [
Text(
"ITENS: ",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 16),
),
Text("$itemsQtd",
style: TextStyle(color: Colors.white, fontSize: 16))
]),
Row(children: [
Text("TOTAL: ",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 18)),
Text("$totalValue MT",
style: TextStyle(color: Colors.white, fontSize: 18))
])
],
),
),
),
Container(
height: MediaQuery.of(context).size.height,
// HERE MY ListView.buider
child: CartProducts(
cart_list: cart_list,
),
),
SizedBox(height: 40),
Container(
width: MediaQuery.of(context).size.width - 30,
child: Row(
children: [
Container(
height: 50,
width: (MediaQuery.of(context).size.width / 2) - 15,
child: ElevatedButton(
onPressed: () {},
child: Text("$totalValue MT",
style: TextStyle(color: sGreenColour)),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(
sGreenLightColour),
shape:
MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
),
),
),
),
),
Container(
height: 50,
width: (MediaQuery.of(context).size.width / 2) - 15,
child: ElevatedButton(
onPressed: () {},
child: Text(
"TERMINAR",
style: TextStyle(color: Colors.white),
),
style: ButtonStyle(
shape:
MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
side: BorderSide(color: sGreenColour),
),
),
),
),
)
],
),
),
SizedBox(height: 10),
],
),
));
}
}
and my ListView.builder
class _CartProductsState extends State<CartProducts> {
#override
Widget build(BuildContext context) {
return ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(), // Disable Scroll
itemCount: widget.cart_list.length,
itemBuilder: (BuildContext context, int index) {
return SigleProduct(
name: widget.cart_list[index]["name"],
picture: widget.cart_list[index]["picture"],
price: widget.cart_list[index]["price"],
unit: widget.cart_list[index]["unit"],
);
});
}
}
// THE ELEMENT OF THE GRIDVIEW
class SigleProduct extends StatelessWidget {
SigleProduct({this.name, this.picture, this.price, this.unit})
: super(key: null);
final name;
final picture;
final price;
final unit;
showAlertDialog(BuildContext context, int id) {
// set up the buttons
Widget cancelButton = TextButton(
child: Text("Não"),
onPressed: () {
Navigator.of(context).pop(); // dismiss dialog
},
);
Widget continueButton = TextButton(
child: Text(
"Sim",
style: TextStyle(color: Colors.red),
),
onPressed: () {
Navigator.of(context).pop(); // dismiss dialog
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text("Producto Removido!"),
));
},
);
// set up the AlertDialog
AlertDialog alert = AlertDialog(
title: Center(child: Text("Alerta!")),
content: Text("Gostaria de Remover o producto do carrinho?"),
actions: [
cancelButton,
continueButton,
],
);
// show the dialog
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
#override
Widget build(BuildContext context) {
return Container(
child: Card(
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
),
child: ListTile(
onTap: () {},
leading: Container(
width: 80,
//color: Colors.amber,
child: Image.asset(picture),
),
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(name,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black,
fontSize: 14)),
Text("$price MT",
style: TextStyle(
fontWeight: FontWeight.bold,
color: sGreenColour,
fontSize: 14)),
],
),
subtitle: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('Unit: $price MT/$unit',
style: TextStyle(color: Colors.black45)),
Text('Qtd: 2/$unit', style: TextStyle(color: Colors.black45)),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
height: 25,
width: 110,
child: ElevatedButton(
onPressed: () {
showAlertDialog(context, 1);
},
child: Text(
"REMOVER",
style: TextStyle(fontSize: 10, color: Colors.white),
),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(Colors.red)),
),
),
Container(
height: 25,
width: 110,
child: ElevatedButton(
onPressed: () {},
child: Text("ACTUALIZAR",
style:
TextStyle(fontSize: 10, color: Colors.white))),
),
],
)
],
),
selected: false,
),
),
);
}
}
Please Help

How to display ListView containing cards when clicking on textbutton flutter

I roughly know how to implement directly the Card ListView, there is no such problem. But, i do not know how to make ListView open by clicking on the TextButton.
Here is some examples:
This is my screen
enter image description here
This is my code
class _CardScreenState extends State<CardScreen> {
var index = 0;
bool buttonClicked = false;
List<String> cards = [
"On hold",
"In progress",
"Needs review",
];
#override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButtonLocation: FloatingActionButtonLocation.endTop,
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.tealAccent,
onPressed: () {
Get.back();
},
child: Icon(Icons.arrow_back),
),
body: Container(
color: Colors.black,
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
alignment: Alignment.topCenter,
child: SizedBox(
height: 150,
width: 500,
child: DecoratedBox(
decoration: BoxDecoration(color: Colors.grey[900]),
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Spacer(),
TextButton(
onPressed: () {
setState(() {
buttonClicked = !buttonClicked;
getCard();
});
},
child: Text(
"On hold",
style: TextStyle(color: Colors.grey[300]),
)),
Spacer(),
TextButton(
onPressed: () {},
child: Text(
"In progress",
style: TextStyle(color: Colors.grey[300]),
)),
Spacer(),
TextButton(
onPressed: () {},
child: Text(
"Needs review",
style: TextStyle(color: Colors.grey[300]),
)),
Spacer(),
TextButton(
onPressed: () {},
child: Text(
"Approved",
style: TextStyle(color: Colors.grey[300]),
)),
Spacer(),
],
),
),
),
),
);
getCard() {
return Expanded(
child: ListView.builder(
itemBuilder: (_, index) => Card(
color: Colors.grey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
//Padding(padding: EdgeInsets.only(left: 5, right: 5)),
Text("data")
],
),
),
),
);
}
}
Тhe expected result is something like this
Demo Widget,
class TabBarDemo extends StatelessWidget {
const TabBarDemo({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return DefaultTabController(
length: 4,
child: Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
backgroundColor: Colors.black,
actions: [
GestureDetector(
onTap: () {},
child: Container(
padding: EdgeInsets.all(8),
decoration:
BoxDecoration(color: Colors.blue, shape: BoxShape.circle),
child: Icon(
Icons.add,
color: Colors.white,
)),
)
],
bottom: TabBar(
tabs: [
Tab(
icon: Text(
"On hold",
style: TextStyle(color: Colors.grey[300]),
)),
Tab(
icon: Text(
"In progress",
style: TextStyle(color: Colors.grey[300]),
)),
Tab(
icon: Text(
"Needs review",
style: TextStyle(color: Colors.grey[300]),
)),
Tab(
icon: Text(
"Approved",
style: TextStyle(color: Colors.grey[300]),
)),
],
),
title: const Text('Tabs Demo'),
),
body: TabBarView(
children: [
const Center(
child: Text(
"On hold",
),
),
const InProgressBody(), // your listView here
Text(
"Needs review",
style: TextStyle(color: Colors.grey[300]),
),
Text(
"Approved",
style: TextStyle(color: Colors.grey[300]),
)
],
),
),
);
}
}
class InProgressBody extends StatelessWidget {
const InProgressBody({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return ListView.builder(
itemBuilder: (context, index) => Container(
height: 100,
child: Text(
"$index",
style: TextStyle(color: Colors.white, fontSize: 33),
),
),
);
}
}
Why dont you use tabbar and tabbarview ?
See:
https://flutter.dev/docs/cookbook/design/tabs

Could not find method android() for arguments [build_1ebi9fgddm6fztg1dwfx76c67$_run_closure2#3e3a1649] on project ':app' of type org.gradle.api.Projec

my build.gradel
It is giving me this error.
** FAILURE: Build failed with an exception.
Where:
Build file 'C:\Users\Kamal\Documents\qr_final\android\app\build.gradle' line: 24
What went wrong:
A problem occurred evaluating project ':app'.
Could not find method android() for arguments [build_1ebi9fgddm6fztg1dwfx76c67$_run_closure2#3e3a1649] on project ':app' of type org.gradle.api.Project.
**
import 'package:flutter/services.dart';
import 'package:scan_qr_easily/page/qr_create_page.dart';
import 'package:scan_qr_easily/page/qr_scan_page.dart';
import 'package:scan_qr_easily/widget/button_widget.dart';
import 'package:url_launcher/url_launcher.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
static final String title = 'QR CODE SCANNER';
#override
Widget build(BuildContext context) => MaterialApp(
debugShowCheckedModeBanner: false,
title: title,
theme: ThemeData(
primaryColor: Colors.blue,
scaffoldBackgroundColor: Colors.white,
),
home: MainPage(title: title),
);
}
class MainPage extends StatefulWidget {
final String title;
const MainPage({
required this.title,
});
#override
_MainPageState createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
#override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
title: Stack(
children: [
Align(
alignment: Alignment.topLeft,
child: Builder(
builder: (context) => IconButton(
icon: Image.asset(
"assets/icon.png",
height: 30,
width: 44,
),
onPressed: () => Scaffold.of(context).openDrawer(),
),
),
),
Center(
child: Align(
alignment: Alignment.topCenter,
child: Text(
widget.title,
style: TextStyle(fontSize: 25.0),
)))
],
),
centerTitle: true,
titleSpacing: 0,
),
drawer: Drawer(
elevation: 10,
child: Container(
decoration: BoxDecoration(color: Colors.blue),
child: Column(
children: <Widget>[
Expanded(
child: Column(children: <Widget>[
SizedBox(
height: 70,
),
Container(
width: 200,
height: 200,
decoration: BoxDecoration(
image: new DecorationImage(
image: AssetImage("assets/qr2.jpeg"),
fit: BoxFit.cover)),
),
ListTile(
title: Text(
'Create QR Code',
style: TextStyle(fontSize: 18.0, color: Colors.white),
),
leading: Icon(
Icons.qr_code,
size: 20.0,
color: Colors.white,
),
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) => QRCreatePage(),
));
},
),
ListTile(
title: Text(
'Scan QR Code',
style: TextStyle(fontSize: 18.0, color: Colors.white),
),
leading: Icon(
Icons.qr_code_scanner_rounded,
size: 20.0,
color: Colors.white,
),
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) => QRScanPage(),
));
},
),
ListTile(
title: InkWell(
child: Text(
'About Developer',
style: TextStyle(fontSize: 18.0, color: Colors.white),
),
onTap: () => launch('https://github.com/kamal614'),
),
leading: Icon(
Icons.people,
size: 20.0,
color: Colors.white,
),
),
ListTile(
title: InkWell(
child: Text(
'Connect on LinkedIn',
style: TextStyle(fontSize: 18.0, color: Colors.white),
),
onTap: () =>
launch('https://www.linkedin.com/in/kamal614/'),
),
leading: Icon(
Icons.add,
size: 20.0,
color: Colors.white,
),
),
]),
),
Container(
child: Align(
alignment: FractionalOffset.bottomCenter,
child: Column(
children: <Widget>[
Divider(),
Center(
child: new InkWell(
child: new Text(
"This app is open source and the Source code can be found at GitHub",
style: TextStyle(fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
onTap: () => launch(
'https://github.com/kamal614/Scan-QR-Bar-code-Easily'),
),
),
],
))),
],
),
),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Image.asset(
"assets/qr.gif",
height: 250.0,
width: 250.0,
),
SizedBox(
height: 20.0,
),
Text(
"What do you want to do today?",
style: TextStyle(fontSize: 20.0, color: Colors.black),
),
SizedBox(
height: 30.0,
),
ButtonWidget(
text: 'Create QR Code',
onClicked: () => Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) => QRCreatePage(),
)),
),
const SizedBox(height: 20),
ButtonWidget(
text: 'Scan QR Code',
onClicked: () => Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) => QRScanPage(),
)),
),
],
),
),
);
}

Trigger slidable from button flutter

I'm using the flutter_slidable package to delete items from a list I have in my app. But I would like to create a button outside of the listview that can trigger these items to display their slidables, but I am unsure how to do this from the documentation provided
https://pub.dev/packages/flutter_slidable
bool isClicked = false;
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
brightness: Brightness.light,
leading: new IconButton(
icon: new Icon(Icons.arrow_back, color: Colors.black),
onPressed: () {
Navigator.of(context).pop();
},
),
backgroundColor: Colors.white,
title: const Text(
'User Cards',
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.black, fontSize: 20.0),
),
actions: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 20.0),
child: Row(
children: <Widget>[
GestureDetector(
onTap: () {
Provider.of<CardBrandProvider>(context, listen: false).clearCardBrand();
Provider.of<Data>(context, listen: false).selectedBrand = null;
Navigator.push(context, MaterialPageRoute(builder: (context) => AddCard()));
},
child: Row(
children: <Widget>[
Icon(
Icons.card_giftcard,
color: Colors.grey[600],
size: 28.0,
),
Icon(
Icons.add,
size: 20.0,
color: Colors.black45,
),
],
)),
],
),
)
],
elevation: 1.0,
centerTitle: true,
),
body: CustomScrollView(
slivers: [
Provider.of<CardProvider>(context, listen: false).cards.isNotEmpty ?
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.only(top: 20),
child: Padding(
padding: const EdgeInsets.only(left: 30.0, right: 26.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'Cards',
style: TextStyle(
fontSize: 17.0,
fontWeight: FontWeight.w500,
fontFamily: 'Lato'),
),
GestureDetector(
onTap: (){
isClicked = true;
},
child: Text(
'Edit',
style: TextStyle(
fontSize: 17.0,
fontWeight: FontWeight.w500,
color: Color.fromRGBO(129, 2, 2, 1),
fontFamily: 'Lato'),
),
),
],
),
),
),
)
:
SliverToBoxAdapter(child: Container(),),
SliverToBoxAdapter(
child: SizedBox(
height: 25,
),
),
Container(
child: SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
var card = getCards(context)[index];
var id = card.Id;
return InkWell(
child: Padding(
padding: const EdgeInsets.only(top: 15, bottom: 15),
child: Column(
children: [
Container(
child: Slidable(
enabled: isClicked,
actionPane: SlidableDrawerActionPane(),
secondaryActions: <Widget>[
IconSlideAction(
caption: 'Delete',
color: Colors.red,
icon: Icons.delete,
onTap: () async {
setState(() {
showSpinner = true;
});
try{
print('$id');
setState(() {
Provider.of<Cards>(context, listen: false).removeIndividualCard(index);
});
} catch(e){
print(e);
setState(() {
showSpinner = true;
});
}
}),
],
child: ListTile(
title: Text('Username$index'),
trailing: Icon(Icons.person),
),
),
),
],
),
),
);
},
childCount: 5,
),
],
),
);
}
}
make a button and handle: Slidable(enabled: false,)

Flutter Dart Bottomsheet error context = context

I hope somebody can help me solve this error;
I used this showModalBottomSheet Widget already, and just tried to implement the structure onto a new site. The error I get and just don't understand in the BottomSheet has something to do with " context = context, " . Do I have to iplement the void funktion somwhere else or should I create a new class that is extending the Header class? Can somebody please help me?
class Home extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomPadding: false,
body: ListView(
children: <Widget>[
Header(),
//SelectOption(),
//Chats(),
//MoodsDetector(),
//NextUp(),
//PostFeed(),
],
),
);
}
}
class Header extends StatelessWidget {
const Header({
Key key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.fromLTRB(25, 50, 50, 25),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Welcome back,',
style: TextStyle(color: secondColor, fontSize: 20),
),
Text(
'Henri',
style: TextStyle(color: mainColor, fontSize: 30),
),
],
),
Container(
width: 50,
height: 50,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
boxShadow: [
BoxShadow(color: secondColor.withOpacity(0.5), blurRadius: 20),
],
),
child: new IconButton(
icon: new Icon(Icons.search),
highlightColor: Colors.pink,
onPressed: _showSearch,
),
),
],
),
);
}
void _showSearch(){
showModalBottomSheet(
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(topRight: Radius.circular(30.0),topLeft: Radius.circular(30.0))
),
isScrollControlled: true,
isDismissible: true,
context: context,
builder: (builder) {
return SingleChildScrollView(
child: Column(
children: <Widget>[
Stack(
children: <Widget>[
SingleChildScrollView(
padding: const EdgeInsets.all(15.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Card(
elevation: 8.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
color: Colors.green,
child: ListTile(
onTap: () {
//open edit profile
},
title: Text(
"Rate your Friendship",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
leading: CircleAvatar(
backgroundImage: AssetImage("assets/images/HenriKlein.jpeg"),
),
trailing: Icon(
Icons.star,
color: Colors.white,
),
),
),
const SizedBox(height:10.0),
Card(
elevation: 4.0,
margin: const EdgeInsets.fromLTRB(32.0, 8.0, 32.0, 16.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
child: Column(
children: <Widget>[
ListTile(
leading: Icon(
Icons.people_outline,
color: Colors.lightGreen,
),
title: Text("Invite to event"),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () {
},
),
sizedBox,
ListTile(
leading: Icon(
Icons.directions_run,
color: Colors.lightGreen,
),
title: Text("Challange Henri"),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () {},
),
sizedBox,
ListTile(
leading: Icon(
Icons.phone_iphone,
color: Colors.lightGreen,
),
title: Text("Text/Call Henri"),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () { },
),
sizedBox,
ListTile(
leading: Icon(
Icons.lock_outline,
color: Colors.lightGreen,
),
title: Text("Delete Friend"),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () {},
),
],
),
),
const SizedBox(height: 5.0),
Center(
child: Text(
"Friens since 09/20/2019",
style: TextStyle(
fontSize: 15.0,
),
textAlign: TextAlign.center,
),
),
SizedBox(height: 20.0),
Container(
height: 40.0,
child: GestureDetector(
onTap: () {
},
child: Material(
borderRadius: BorderRadius.circular(50.0),
shadowColor: Colors.black,
color: Colors.green,
elevation: 7.0,
child: Center(
child: Text(
'27 mutural friends', //Login Button
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat'),
),
),
),
),
),
],
),
),
],
),
],
),
);
});
}
}
You are getting the error because context is not defined in _showSearch.
You should modify the function definition and add context as a parameter as follows:
void _showSearch(BuildContext context) {
...
And when you are calling, you must pass context of the widget from where you are calling it, as follows:
child: new IconButton(
icon: new Icon(Icons.search),
highlightColor: Colors.pink,
onPressed: () {
_showSearch(context); //here
},
),