OnPressed is not working in Flutter with firebase - android

There is no error in this code but doesn't work.Can someone please provide an example code of what's needed to solve for this? ➡︎
onPressed: () {widget.snapshot['twitter'];}
import 'package:cached_network_image/cached_network_image.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
class PostDetails extends StatefulWidget {
DocumentSnapshot snapshot;
PostDetails({required this.snapshot});
#override
_PostDetailsState createState() => _PostDetailsState();
}
class _PostDetailsState extends State<PostDetails> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
leading: InkWell(
onTap: () {
Navigator.pop(context);
},
child: const Icon(Icons.arrow_back_ios, color: Colors.redAccent),
),
title: Row(
children: [
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: CachedNetworkImageProvider(
widget.snapshot['imgUrl'],
),
fit: BoxFit.cover,
),
),
),
SizedBox(width: 15),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.snapshot['name'],
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
SizedBox(height: 3),
Text(
widget.snapshot['job'],
style: const TextStyle(
fontSize: 13,
fontWeight: FontWeight.bold,
color: Colors.black45,
),
),
],
),
],
),
actions: [
IconButton(
icon: FaIcon(FontAwesomeIcons.twitter),
onPressed: () {
widget.snapshot['twitter'];
},
)
],
// centerTitle: false,
),
When I click the button[onPressed],I want to display the code ---widget.snapshot['twitter'];.
What am I doing wrong here? I'd really appreciate some help. Thank you.

Related

How do i put a horizontal listview of boxdecoration under another boxdecoration?

Hellog guys im new to flutter and wanted to make a homepage with a horizontal listview below a boxdecoration for my health app.
here is my UI that i build in figma
i want to make my homepage to be like that but cant quite understand how to do it.
btw this is my current homepage so far
and this is my code
//import 'dart:js';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_navigation/get_navigation.dart';
import 'package:medreminder/NewsArticle/news_home.dart';
import 'package:medreminder/Recipe/recipe_home.dart';
import 'package:medreminder/Reminder/ui/theme.dart';
import 'package:medreminder/TipsAndTricks/screens/tips_screen.dart';
import 'Reminder/home_reminder.dart';
import 'Reminder/ui/widgets/button.dart';
import 'package:medreminder/main.dart';
import 'package:medreminder/home_page.dart';
void main() {
// debugPaintSizeEnabled = true;
runApp(const HomePage());
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Mr. Health App"),
backgroundColor: Color(0XFF0080FE),
),
body: Stack(
alignment: Alignment.topCenter,
children: [
Image.asset('images/MenuImg.jpg'),
Container(
height: 250,
width: 310,
margin: const EdgeInsets.only(top: 150),
padding: const EdgeInsets.only(
left: 20,
right: 20,
top: 15,
bottom: 15,
),
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(25.0)),
color: context.theme.backgroundColor,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
spreadRadius: 2,
blurRadius: 5,
offset: const Offset(0, 6),
),
],
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Column(
children: [
IconButton(
icon: Image.asset('images/reminder.png'),
iconSize: 45,
onPressed: () {
Navigator.of(context, rootNavigator: true).push(
MaterialPageRoute(builder: (context) => const ReminderHomePage()),
);
},
),
Text("Medicine\nReminder", style: normalStyle,)
],
),
Column(
children: [
IconButton(
icon: Image.asset('images/news.png'),
iconSize: 45,
onPressed: () {
Navigator.of(context, rootNavigator: true).push(
MaterialPageRoute(builder: (context) => NewsHomePage()),
);
},
),
Text(" News \n& Article", style: normalStyle)
],
),
Column(
children: [
IconButton(
icon: Image.asset('images/recipe.png'),
iconSize: 45,
onPressed: () {
Navigator.of(context, rootNavigator: true).push(
MaterialPageRoute(builder: (context) => RecipeHomePage()),
);
},
),
Text("Healty Food \n Recipe", style: normalStyle)
],
),
],
),
SizedBox(height: 10,),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Column(
children: [
IconButton(
icon: Image.asset('images/tips.png'),
iconSize: 45,
onPressed: () {
Navigator.of(context, rootNavigator: true).push(
MaterialPageRoute(builder: (context) => const TipsList()),
);
},
),
Text("Tips &\n Tricks", style: normalStyle,)
],
),
Column(
children: [
IconButton(
icon: Image.asset('images/about.png'),
iconSize: 45,
onPressed: () {
},
),
Text("About Us\n", style: normalStyle)
],
),
Column(
children: [
IconButton(
icon: Image.asset('images/recipe.png'),
iconSize: 45,
onPressed: () {},
),
Text("Healty Food \n Recipe", style: normalStyle)
],
),
],
)
],
),
),
],
));
}
}
i hope you guys can help me. thankyou so much
A horizontal list view can be created by ListView.builder widget. By default scroll direction of this list is vertical hence you have to change it to horizontal : -
scrollDirection: Axis.horizontal,
Full Code : -
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'ListView',
theme: ThemeData(
primarySwatch: Colors.blue,
),
debugShowCheckedModeBanner: false,
home: const View(),
);
}
}
class View extends StatefulWidget {
const View({super.key});
#override
State<View> createState() => _ViewState();
}
class _ViewState extends State<View> {
List doctorName = ["A", "B", "C"];
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color.fromARGB(255, 236, 230, 230),
body: Padding(
padding: const EdgeInsets.only(top: 550),
child: SizedBox(
height: 240,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: doctorName.length,
itemBuilder: ((context, index) {
return (Container(
margin: EdgeInsets.only(
top: 15,
bottom: 15,
left: 25,
right: index == 2 ? 25 : 0),
padding: const EdgeInsets.only(left: 15, right: 15),
width: 360,
decoration: BoxDecoration(
color: Colors.white,
borderRadius:
const BorderRadius.all(Radius.circular(20.0)),
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.black.withOpacity(0.3),
blurRadius: 5.0,
spreadRadius: 2.0,
offset: const Offset(0.0, 6.0)),
]),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const CircleAvatar(
radius: 45.0,
child: Icon(
Icons.person,
size: 45,
),
),
const SizedBox(
width: 20,
),
Column(
children: [
const SizedBox(
height: 40,
),
Text(
doctorName[index],
style: const TextStyle(
fontSize: 22,
fontWeight: FontWeight.w700),
),
const SizedBox(
height: 10,
),
const Text(
'Text 1',
style: TextStyle(
fontSize: 18,
),
),
const Text(
'Text 2',
style: TextStyle(
fontSize: 18,
),
),
const SizedBox(
height: 10,
),
],
)
],
),
const Divider(
color: Colors.black,
thickness: 1.0,
),
const SizedBox(
height: 10,
),
const Text(
'Body ...',
style: TextStyle(
fontSize: 20, fontWeight: FontWeight.w400),
),
],
),
));
})),
),
));
}
}
Output : -

RenderFlex Overflowed when I try to resize screen to smaller one

I am trying to build a page which contains 6 buttons and a background image .My code working perfectly fine . I am creating it for flutter web so I am running it on Edge .When i try resizing the full screen to smaller one i Get the ErroR rENDERED fFlex Overflowed .I tried using expanded widget but i got an error .Can u help me rectify this minor bug.
The error is as shown in the image below.
Here is my Code:-
import 'dart:html';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'restaurant.dart';
class mainpage extends StatefulWidget {
#override
_mainpageState createState() => _mainpageState();
}
class _mainpageState extends State<mainpage> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar:AppBar(
title:const Center(child: Text("Food express")),
backgroundColor: Colors.black54,
),
body: Container(
decoration:const BoxDecoration(
image:DecorationImage(
image: AssetImage('image/foood.jpg'),
fit : BoxFit.cover,
),
),
child: Column(
children: [
Row(
children: [
const SizedBox(height:400,width:450),
FlatButton(
onPressed: () {
Navigator.push(context,MaterialPageRoute(builder:(context){
return Restaurant();
}));
},
color: Colors.black26,
child: const Text('Restaurant',
style: TextStyle(
color:Colors.white,
),
),
padding: const EdgeInsets.all(40),
),
const SizedBox(width:50,height:20),
FlatButton(
onPressed: () {},
color: Colors.black26,
child: const Text('Restaurant',
style: TextStyle(
color:Colors.white,
),
),
padding: const EdgeInsets.all(40),
),
const SizedBox(width:50,height:20),
FlatButton(
onPressed: () {},
color: Colors.black26,
child: const Text('Restaurant',
style: TextStyle(
color:Colors.white,
),
),
padding: const EdgeInsets.all(40),
)
],
),
Row(
children:[
const SizedBox(height:100,width:450),
FlatButton(
onPressed: () {},
color: Colors.black26,
child: const Text('Restaurant',
style: TextStyle(
color:Colors.white,
),
),
padding: const EdgeInsets.all(40),
),
const SizedBox(width:50,height:20),
FlatButton(
onPressed: () {},
color: Colors.black26,
child: const Text('Restaurant',
style: TextStyle(
color:Colors.white,
),
),
padding: const EdgeInsets.all(40),
),
const SizedBox(width:50,height:20),
FlatButton(
onPressed: () {},
color: Colors.black26,
child: const Text('Restaurant',
style: TextStyle(
color:Colors.white,
),
),
padding: const EdgeInsets.all(40),
),
const SizedBox(width:50,height:20),
]
)
],
),
),
);
}
}

How to shift image top bottom in flutter

I was trying to make this page but this design in last is not shifting to the last bottom, I've tried padding but this doesn't look good and also I've tried positioned widget but it is showing some error please someone tell how I can shift that design to bottom last
this is my git repo: https://github.com/cryptic-exe/Otp_verfication
this is my code:
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
debugShowCheckedModeBanner: false,
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String dropdownValue = 'English';
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(
child: Column(
children: [
Icon(
Icons.photo_outlined,
size: 100.0,
),
Padding(
padding: const EdgeInsets.only(top: 40.0),
child: Text(
'Please Select Your Language',
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 20.0),
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 20),
child: Text(
'You can change the language \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t at any time',
style: TextStyle(
fontWeight: FontWeight.w300, fontSize: 15.0),
),
),
Padding(
padding: const EdgeInsets.only(top: 9.0),
child: Container(
width: 200,
padding: const EdgeInsets.only(left: 10.0, right: 10.0),
decoration: BoxDecoration(
border: Border.all(),
),
child: DropdownButton<String>(
value: dropdownValue,
icon: const Icon(Icons.arrow_drop_down_outlined),
isExpanded: true,
iconSize: 30,
elevation: 16,
style: const TextStyle(color: Colors.black),
onChanged: (String? newValue) {
setState(() {
dropdownValue = newValue!;
});
},
items: <String>[
'English',
'Hindi',
'French',
'Spanish',
'Russian',
'Arabic'
].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(
value,
style: TextStyle(
fontSize: 20,
letterSpacing: 0.9,
fontWeight: FontWeight.w300),
),
);
}).toList(),
),
),
),
Padding(
padding: const EdgeInsets.all(20.0),
child: Container(
width: 200,
padding: const EdgeInsets.only(left: 10.0, right: 10.0),
decoration: BoxDecoration(
color: Colors.deepPurple,
border: Border.all(),
),
child: TextButton(
onPressed: () {},
child: Text(
'NEXT',
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
fontWeight: FontWeight.w400,
letterSpacing: 0.9),
),
),
),
),
],
),
),
Stack(
children: [
Positioned.fill(
child: Container(
width: 393,
child: Image(
image: AssetImage('Images/design2.png'),
fit: BoxFit.fill,
),
),
),
Positioned(
child: Container(
width: 393,
child: Image(
image: AssetImage('Images/design1.png'),
colorBlendMode: BlendMode.overlay,
fit: BoxFit.fill,
),
),
),
],
),
],
),
);
}
}
you can use bottomSheet to place your image.
Add the below code inside your Scaffold
bottomSheet: Container(
width: double.infinity,
child: Image(
image: AssetImage('Images/design1.png'),
colorBlendMode: BlendMode.overlay,
fit: BoxFit.fill,
),
),
You can also use a spacer to push the content down
https://api.flutter.dev/flutter/widgets/Spacer-class.html
On mobile so I cannot give snippet

Jumping to desired screens on pressing an item in Bottom Navigation Bar

I am writing a code in flutter and the screen with the bottom navigation bar looks like this.
What I want is that whenever I press the home button from the bottom navigation bar it should jump to the home screen, similarly for other screens like clicking the caregiver icon I want to move to Caregiver Screen and so on for others. I cannot figure this out by using BottomNaviagtionBar. Please help me out.
Code for Home Screen that contains my bottom navigation bar:
import 'package:epicare/HistoryScreen.dart';
import 'package:epicare/ProfileScreen.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_switch/flutter_switch.dart';
import 'package:charts_flutter/flutter.dart' as charts;
import 'CaregiverScreen.dart';
class HomeScreen extends StatefulWidget {
#override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
#override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Scaffold(
appBar: AppBar(),
drawer: new Drawer(),
body: Column(),
bottomNavigationBar: Container(
height: 70,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(20), topLeft: Radius.circular(20)),
boxShadow: [
BoxShadow(color: Colors.black38, spreadRadius: 0, blurRadius: 10),
],
),
child: ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20.0),
topRight: Radius.circular(20.0),
),
child: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
backgroundColor: Colors.white,
unselectedFontSize: 10,
selectedFontSize: 10,
selectedLabelStyle: optionStyle,
currentIndex: _currentIndex,
selectedItemColor: const Color(0xffd4d411),
unselectedItemColor: const Color(0xffd4d411),
onTap: onTabTapped,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: ImageIcon(
AssetImage('assets/images/home.png'),
color: const Color(0xffd4d411),
),
title: new Text(
'Home',
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 10,
color: Colors.black,
),
),
),
BottomNavigationBarItem(
icon: ImageIcon(
AssetImage(
'assets/images/caregiver.png',
),
color: const Color(0xffd4d411),
),
title: new Text(
'Caregiver',
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 10,
color: Colors.black,
),
),
),
BottomNavigationBarItem(
icon: ImageIcon(
AssetImage('assets/images/history.png'),
color: const Color(0xffd4d411),
),
title: Text(
'History',
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 10,
color: Colors.black,
),
),
),
BottomNavigationBarItem(
icon: ImageIcon(
AssetImage('assets/images/profile.png'),
color: const Color(0xffd4d411),
),
title: Text(
'Profile',
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 10,
color: Colors.black,
),
),
),
],
),
),
),
);
}
void onTabTapped(int index) {
setState(() {
_currentIndex = index;
});
}
}
P.S: I am still learning flutter
Thank you in advance!
Try to do this:
in your state class, put this at the beginning:
int _currentIndex = 0;
At the beginning of you build:
Widget build(BuildContext context) {
final _widgetOptions = [
Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Stack(
children: [ Container( padding: EdgeInsets.symmetric(vertical: 22,
horizontal: 47),
CaregiverScreen(),
HistoryScreen(),
ProfileScreen()
];
This should be your body:
body: _widgetOptions.elementAt(_currentIndex),

Dialog with top gravity and overlay line in flutter

Trying to make this UI, unable to set gravity or position on dialog. I don't have any idea to make overlay doted line.
class DashboardScreen extends StatefulWidget {
#override
_DashboardScreenState createState() => _DashboardScreenState();
}
class _DashboardScreenState extends State<DashboardScreen> {
#override
Widget build(BuildContext context) {
return Scaffold(
body:Container(),
appBar: AppBar(centerTitle: false,
automaticallyImplyLeading: false,
backgroundColor: Colors.white,
elevation: 0,
title: Text(
"Inventory",
textScaleFactor: 1.3,
style: TextStyle(color: Colors.black87, fontFamily: "light"),
),
actions: [
IconButton(
onPressed: (){},
color: Colors.black,
icon: ImageIcon(
AssetImage('assets/images/camera_outline.png'),
size:50,
),
),
IconButton(
onPressed: (){},
color: Colors.black,
icon: ImageIcon(
AssetImage('assets/images/camera_outline.png'),
size:50,
),
),
IconButton(
onPressed: (){
// openAlertBox();
showDialog(context: context,
builder: (_) =>Dialog(
backgroundColor: Colors.transparent,
insetPadding: EdgeInsets.all(20),
child: Column(
children: <Widget>[
Container(
width: double.infinity,
height: 150,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.white
),
padding: EdgeInsets.fromLTRB(20, 50, 20, 20),
child: Text("You can make cool stuff!",
style: TextStyle(fontSize: 24),
textAlign: TextAlign.center
),
),
],
)
));
},
color: Colors.black,
icon: ImageIcon(
AssetImage('assets/images/camera_outline.png'),
size:50,
),
)
],
),
);
}
}
How it is looking.

Categories

Resources