Flutter showModalBottomSheet does not allow transparent background container - flutter

Am I using some widget here incorrectly or is this an issue with showModalBottomSheet?
As you can see here in the screenshots, the test code I've included displays a button in a 70% transparent container. This looks correct in main body. However, when you tap the Open Bottom Sheet button to display the showModalBottomSheet() function you'll see that that exact same button in a container with 70% transparent bg color is now 100% opaque.
Why is the opacity of the container being ignored in the showModalBottomSheet widget tree?
I've tried using Opacity widget and a Stack, but transparency does not seem to be allowed in a showModalBottomSheet?
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: BottomSheet(),
);
}
}
class BottomSheet extends StatelessWidget {
const BottomSheet({
Key? key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
void _showBottomSheet() {
showModalBottomSheet(
context: context,
builder: (context) {
return Container(
height: MediaQuery.of(context).size.height * 0.75,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.only(top: 27.0, bottom: 27.0),
child: Text(
'Select',
style: TextStyle(
fontSize: 20.0,
color: Colors.blue,
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 24.0, right: 24.0),
child: GridView.count(
crossAxisCount: 3,
mainAxisSpacing: 25.0,
crossAxisSpacing: 25.0,
padding: EdgeInsets.only(
bottom: 100.0,
),
children: [
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
],
),
),
),
Container(
width: double.infinity,
height: 161.0,
color: Colors.white.withOpacity(0.3),
child: Padding(
padding: const EdgeInsets.only(
left: 24.0,
right: 24.0,
),
child: Center(
child: OutlinedButton(
child: Text(
'Button in container with 70% transparent bg ignored',
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
),
textAlign: TextAlign.center,
),
onPressed: () {},
style: OutlinedButton.styleFrom(
backgroundColor: Colors.blue,
minimumSize: Size(double.infinity, 52.0),
),
),
),
),
),
],
),
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(32.0),
topRight: const Radius.circular(32.0),
),
),
);
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(32.0),
topRight: const Radius.circular(32.0),
),
),
barrierColor: Color.fromRGBO(0, 0, 0, 0.9),
isScrollControlled: true,
);
}
return Scaffold(
backgroundColor: Colors.indigo,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
child: Text(
'Open bottom sheet',
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
),
),
onPressed: _showBottomSheet,
),
SizedBox(
height: 30.0,
),
Container(
width: double.infinity,
height: 161.0,
color: Colors.white.withOpacity(0.3),
child: Padding(
padding: const EdgeInsets.only(
left: 24.0,
right: 24.0,
),
child: Center(
child: OutlinedButton(
child: Text(
'Button in container with 70% transparent bg',
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
),
textAlign: TextAlign.center,
),
onPressed: () {},
style: OutlinedButton.styleFrom(
backgroundColor: Colors.blue,
minimumSize: Size(double.infinity, 52.0),
),
),
),
),
),
],
),
),
);
}
}

As you can see here, it appears to be a bug in Flutter's showModalBottomSheet().
To overcome this, I built my own bottom sheet in a Stack to get the transparency affect I needed on the bottom sheet button.

Related

How do I put a button in a block in flutter?

Used expanded, container. Does not work. I tried to put the Elevated Button in Expanded. And all the time that child can't use something else. Most likely, I don't quite understand the structure. I tried to put the Elevated Button in Expanded.
import 'package:percent_indicator/percent_indicator.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MaterialApp(
debugShowCheckedModeBanner: false,
home: Pomodoro(),
));
}
class Pomodoro extends StatefulWidget {
const Pomodoro({Key? key}) : super(key: key);
#override
State<Pomodoro> createState() => _PomodoroState();
}
class _PomodoroState extends State<Pomodoro> {
double percent = 0;
// ignore: non_constant_identifier_names, unused_field
static int TimeInMinut = 25;
// ignore: non_constant_identifier_names
int TimeInSec = TimeInMinut = 60;
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [Color(0xff1542bf), Color(0xff51a8ff)],
begin: FractionalOffset(0.5, 1)),
),
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Padding(
padding: EdgeInsets.only(top: 25.0),
child: Text(
'Pomodoro Clock',
style: TextStyle(color: Colors.white, fontSize: 40.0),
),
),
Expanded(
child: SizedBox(
height: 20.0,
width: 50.0,
child: CircularPercentIndicator(
percent: percent,
animation: true,
animateFromLastPercent: true,
radius: 90.0,
lineWidth: 20.0,
progressColor: Colors.white,
center: Text(
'$TimeInMinut',
style: const TextStyle(
color: Colors.white, fontSize: 30.0),
),
),
),
),
Expanded(
child: Container(
width: double.infinity,
decoration: const BoxDecoration(
color: Color.fromARGB(255, 163, 48, 48),
borderRadius: BorderRadius.only(
topRight: Radius.circular(30.0),
topLeft: Radius.circular(30.0)),
),
child: Padding(
padding: const EdgeInsets.only(
top: 30.0, left: 20.0, right: 20.0),
child: Row(
children: [
Expanded(
child: Column(
children: const [
Text(
'Study Time',
style: TextStyle(
fontSize: 30.0,
),
),
SizedBox(
height: 10.0,
),
Text(
'25',
style: TextStyle(
fontSize: 80.0,
),
),
],
),
),
Expanded(
child: Column(
children: const [
Text(
'Pause Timer',
style: TextStyle(
fontSize: 30.0,
),
),
Text(
'5',
style: TextStyle(
fontSize: 80.0,
),
),
Expanded(
child: Padding(
padding: EdgeInsets.symmetric(vertical: 10.0),
child: Text(
'hello',
),
))
],
),
),
],
),
),
),
),
Container(
padding: const EdgeInsets.symmetric(vertical: 0.0),
child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100.0),
),
),
child: const Padding(
padding: EdgeInsets.all(20.0),
child: Text(
'start studing',
style: TextStyle(color: Colors.white, fontSize: 22.0),
),
),
),
),
]),
),
),
);
}
}
If you like to use Expanded on Text(hello) widget. You need to get constrains from top level/parent widget, but this is not the solution you like to archive.
I will recommend checking /layout/constraints
As for the answer, you need to wrap Row widget Column to place another child just after the row widget. It could be skipped if you we had same color as background.
import 'package:percent_indicator/percent_indicator.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MaterialApp(
debugShowCheckedModeBanner: false,
home: Pomodoro(),
));
}
class Pomodoro extends StatefulWidget {
const Pomodoro({Key? key}) : super(key: key);
#override
State<Pomodoro> createState() => _PomodoroState();
}
class _PomodoroState extends State<Pomodoro> {
double percent = 0;
// ignore: non_constant_identifier_names, unused_field
static int TimeInMinut = 25;
// ignore: non_constant_identifier_names
int TimeInSec = TimeInMinut = 60;
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [Color(0xff1542bf), Color(0xff51a8ff)],
begin: FractionalOffset(0.5, 1)),
),
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Padding(
padding: EdgeInsets.only(top: 25.0),
child: Text(
'Pomodoro Clock',
style: TextStyle(color: Colors.white, fontSize: 40.0),
),
),
Expanded(
child: SizedBox(
height: 20.0,
width: 50.0,
child: CircularPercentIndicator(
percent: percent,
animation: true,
animateFromLastPercent: true,
radius: 90.0,
lineWidth: 20.0,
progressColor: Colors.white,
center: Text(
'$TimeInMinut',
style: const TextStyle(
color: Colors.white, fontSize: 30.0),
),
),
),
),
Expanded(
child: Container(
width: double.infinity,
padding: const EdgeInsets.only(
top: 30.0, left: 20.0, right: 20.0),
decoration: const BoxDecoration(
color: Color.fromARGB(255, 163, 48, 48),
borderRadius: BorderRadius.only(
topRight: Radius.circular(30.0),
topLeft: Radius.circular(30.0)),
),
child: Column(
children: [
Row(
children: [
Expanded(
child: Column(
children: const [
Text(
'Study Time',
style: TextStyle(
fontSize: 30.0,
),
),
SizedBox(
height: 10.0,
),
Text(
'25',
style: TextStyle(
fontSize: 80.0,
),
),
],
),
),
Column(
children: const [
Text(
'Pause Timer',
style: TextStyle(
fontSize: 30.0,
),
),
Text(
'5',
style: TextStyle(
fontSize: 80.0,
),
),
Padding(
padding: EdgeInsets.symmetric(vertical: 10.0),
child: Text(
'hello',
),
)
],
),
],
),
Container(
height: 100,
width: 200,
padding: const EdgeInsets.symmetric(vertical: 0.0),
child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100.0),
),
),
child: const Padding(
padding: EdgeInsets.all(20.0),
child: Text(
'start studing',
style: TextStyle(
color: Colors.white, fontSize: 22.0),
),
),
),
),
],
),
),
),
]),
),
),
);
}
}

How can I have an animated SliverAppBar like this?

I want these animation between to be smooth, I tried using AnimatedSize, AnimatedOpacity and AnimatedPositioned but there were few errors. And I don't know how to use these with SliverAppBar. In other examples I saw people using LayoutBuilder but they didn't share the full code so I couldn't test it. I will share my code snippet but it has a really odd transition between the two states.
I want CircleAvatar to become smaller and change position
I want Icon(Icons.arrow_back) and Text('Previous Page') to disappear.
I also want my name and job to disappear.
I want that three Containers to become smaller and change position.
import 'package:flutter/material.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: 'Dialog Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: CustomScrollView(
slivers: [
SliverAppBar(
elevation: 0,
pinned: true,
expandedHeight: 190,
collapsedHeight: kToolbarHeight + 8,
flexibleSpace: FlexibleSpaceBar(
collapseMode: CollapseMode.none,
centerTitle: true,
titlePadding: EdgeInsetsDirectional.only(
start: 20.0,
end: 20.0,
top: 12.0,
bottom: 12.0,
),
title: SafeArea(
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
CircleAvatar(
radius: 16,
),
Row(
children: [
Container(
decoration: BoxDecoration(
color: Colors.white10,
borderRadius: BorderRadius.all(
Radius.circular(12),
),
),
padding: EdgeInsets.all(8.0),
child: Icon(Icons.person),
),
SizedBox(
width: 8,
),
Container(
decoration: BoxDecoration(
color: Colors.white10,
borderRadius: BorderRadius.all(
Radius.circular(12),
),
),
padding: EdgeInsets.all(8.0),
child: Icon(Icons.menu),
),
SizedBox(
width: 8,
),
Container(
decoration: BoxDecoration(
color: Colors.white10,
borderRadius: BorderRadius.all(
Radius.circular(12),
),
),
padding: EdgeInsets.all(8.0),
child: Icon(Icons.message),
),
],
),
],
),
],
),
),
background: SafeArea(
child: Column(
children: [
Container(
alignment: Alignment.topLeft,
child: Row(
children: [
IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {},
),
Text(
'PREVIOUS PAGE',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(
left: 20,
top: 12,
bottom: 24,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CircleAvatar(
radius: 20,
),
SizedBox(
width: 12,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Sertan Hakkı İmamoğlu',
style: TextStyle(
fontSize: 18,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
Text(
'Student',
style: TextStyle(
fontSize: 14,
color: Colors.grey,
),
),
SizedBox(
height: 12,
),
Row(
children: [
Container(
decoration: BoxDecoration(
color: Colors.white10,
borderRadius: BorderRadius.all(
Radius.circular(12),
),
),
padding: EdgeInsets.symmetric(
horizontal: 34,
vertical: 12,
),
child: Icon(Icons.menu),
),
SizedBox(
width: 4,
),
Container(
decoration: BoxDecoration(
color: Colors.white10,
borderRadius: BorderRadius.all(
Radius.circular(12),
),
),
padding: EdgeInsets.symmetric(
horizontal: 34,
vertical: 12,
),
child: Icon(Icons.person),
),
SizedBox(
width: 4,
),
Container(
decoration: BoxDecoration(
color: Colors.white10,
borderRadius: BorderRadius.all(
Radius.circular(12),
),
),
padding: EdgeInsets.symmetric(
horizontal: 34,
vertical: 12,
),
child: Icon(Icons.message),
),
],
)
],
)
],
),
),
],
),
),
),
),
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Container(
color: index.isOdd ? Colors.white : Colors.black12,
height: 100.0,
child: Center(
child: Text('$index', textScaleFactor: 5),
),
);
},
childCount: 20,
),
),
],
),
),
);
}
}
Here's my take on your issue, as suggested by pskink I've used a SliverPersistentHeader and tried to make it responsive so when the size is reducing it has a bit of an animation.
Sample Code
class CustomPageHeader extends SliverPersistentHeaderDelegate {
CustomPageHeader({
required double collapsedHeight,
required double expandedHeight,
}) : minExtent = collapsedHeight, maxExtent = expandedHeight;
#override
final double minExtent;
#override
final double maxExtent;
Widget _buildBtn(IconData icon, double scale) {
double horizontal = 34.0 * scale;
horizontal = horizontal < 8 ? 8.0 : horizontal;
double vertical = 12.0 * scale;
vertical = vertical < 8 ? 8.0 : vertical;
return Container(
decoration: const BoxDecoration(
color: Colors.white10,
borderRadius: BorderRadius.all(
Radius.circular(12),
),
),
padding: EdgeInsets.symmetric(horizontal: horizontal, vertical: vertical),
child: Icon(icon),
);
}
#override
Widget build(
BuildContext context, double shrinkOffset, bool overlapsContent) {
final theme = Theme.of(context);
final backgroundColor =
theme.appBarTheme.backgroundColor ?? theme.colorScheme.primary;
final scale = 1 - shrinkOffset / maxExtent;
final isReduced = shrinkOffset >= maxExtent * 0.12;
final wrappedBtns = Wrap(
spacing: 8,
children: [
_buildBtn(Icons.menu, scale),
_buildBtn(Icons.person, scale),
_buildBtn(Icons.message, scale),
],
);
double avatarRadius = 20.0 * scale;
avatarRadius = avatarRadius > 16 ? avatarRadius : 16.0;
return Container(
padding: const EdgeInsets.only(
left: 20,
top: 12,
bottom: 12,
),
color: backgroundColor,
child: Column(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CircleAvatar(radius: avatarRadius),
!isReduced
? const SizedBox(width: 12)
: Expanded(child: Container()),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (!isReduced)
Text(
'Sertan Hakkı İmamoğlu',
style: TextStyle(
fontSize: 18 * scale,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
if (!isReduced)
Text(
'Student',
style: TextStyle(
fontSize: 14 * scale,
color: Colors.grey,
),
),
],
),
if (isReduced) wrappedBtns,
],
),
Flexible(
child: Container(
constraints: const BoxConstraints(maxHeight: 12),
),
),
if (!isReduced) wrappedBtns,
],
),
);
}
#override
bool shouldRebuild(_) => true;
}
Use it in your sliver list like this:
SliverPersistentHeader(
pinned: true,
delegate: CustomPageHeader(
collapsedHeight: kToolbarHeight + 8,
expandedHeight: 190,
),
),
Try the full test code on DartPad
The code is perfectible but should help you enough so you can improve it and continue by yourself.

Flutter - Align widget all the way to the end of a card view. (View image included)

how can I get the flat button to fill the area under the divider all the way to the end of the card, it appears to not be able to go any further down.
See the white space under the FlatButton? I want it to look like the FlatButton is the end.
Doesn't have to be a flat button, any widget with onTap/press/(or a something hack-ish with gesture detector) listener would be fine.
Dart code is ->
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(4.0),
child: Card(
elevation: 5,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(15))
),
child: Container(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 24, bottom: 16),
child: Text(_label, style: TextStyle(fontSize: 24, color: Color.fromARGB(190, 0, 0, 0), fontWeight: FontWeight.bold)),
),
Divider(color: Colors.black26, height: 2,),
Padding(
padding: const EdgeInsets.all(24.0),
child: Text(_information, style: TextStyle(fontSize: 20, color: Colors.black87)),
),
Divider(color: Colors.black26, height: 2,),
SizedBox(width: double.infinity, child: FlatButton(onPressed: () => _onTap(), color: Color.fromARGB(50, 100, 100, 100), child: Text('Done', style: TextStyle()), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5))))
],
),
),
),
);
}
Please see the code below, I'm using InkWell & Container :
import 'package:flutter/material.dart';
final Color darkBlue = const Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
//theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
String _label = "";
String _information = "";
return Padding(
padding: const EdgeInsets.all(4.0),
child: Card(
elevation: 5,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(15))),
child: Container(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 24, bottom: 16),
child: Text(_label,
style: TextStyle(
fontSize: 24,
color: Color.fromARGB(190, 0, 0, 0),
fontWeight: FontWeight.bold)),
),
Divider(
color: Colors.black26,
height: 2,
),
Padding(
padding: const EdgeInsets.all(24.0),
child: Text(_information,
style: TextStyle(fontSize: 20, color: Colors.black87)),
),
Divider(
color: Colors.black26,
height: 2,
),
Spacer(),
InkWell(
onTap: () {}, //_onTap(),
child: Container(
width: double.infinity,
height: 40,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: const Color.fromARGB(50, 100, 100, 100)),
child: const Center(child: Text('Done', style: TextStyle())),
),
)
],
),
),
),
);
}
}
I solved my code like this, setting a height factor it did what i wanted automatically.
SizedBox(width: double.infinity, height: 60, child:
FlatButton(onPressed: () => _onTap(), color: Colors.transparent, child:
Text('Done', style: TextStyle()), shape: RoundedRectangleBorder(borderRadius:
BorderRadius.only(bottomLeft: Radius.circular(15), bottomRight: Radius.circular(15)))))
Only downside is that you have to specify a height rather than letting the widget adjust that based on content. Although there is probably a workaround for that.

Navigator.push() shows a Black Screen

I am trying to make a fruithero flutter app but while changing my main page to another page, It shows only a black screen on my android emulator in laptop and on my phone, but in https://flutlab.io/ it shows perfectly, What is the problem that the app is not working on local emulator or in my phone but working on online IDE
Showing an Eror like this: -
There are multiple heroes that share the same tag within a subtree.
main.dart
import 'package:flutter/material.dart';
import './detailsPage.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
debugShowCheckedModeBanner: false,
);
}
}
class MyHomePage extends StatefulWidget {
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xFF21BFBD),
body: ListView(
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 15.0, left: 10.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
icon: Icon(Icons.arrow_back_ios),
color: Colors.white,
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailsPage(),
),
);
},
),
Container(
width: 125.0,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
icon: Icon(Icons.filter_list),
color: Colors.white,
onPressed: () {},
),
IconButton(
icon: Icon(Icons.menu),
color: Colors.white,
onPressed: () {},
),
],
),
),
],
),
),
SizedBox(
height: 25.0,
),
Padding(
padding: EdgeInsets.only(left: 40.0),
child: Row(
children: <Widget>[
Text(
'Healthy',
style: TextStyle(
fontFamily: 'Mont',
color: Colors.white,
fontSize: 25.0,
fontWeight: FontWeight.bold),
),
SizedBox(width: 10.0),
Text(
'Food',
style: TextStyle(
fontFamily: 'Mont', color: Colors.white, fontSize: 25.0),
),
],
),
),
SizedBox(
height: 40.0,
),
Container(
height: MediaQuery.of(context).size.height - 185.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius:
BorderRadius.only(topLeft: Radius.circular(75.0))),
child: ListView(
primary: false,
padding: EdgeInsets.only(left: 25.0, right: 20.0),
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 45.0),
child: Container(
height: MediaQuery.of(context).size.height / 1.68,
child: ListView(
children: <Widget>[
_buildFoodItem('images/one.png', 'Salmon', '\$24.0'),
_buildFoodItem('images/two.png', 'Spring', '\$22.0'),
_buildFoodItem('images/three.png', 'Sprite', '\$34.0'),
_buildFoodItem('images/one.png', 'Mut', '\$12.0')
],
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
height: 65.0,
width: MediaQuery.of(context).size.width / 6,
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey,
style: BorderStyle.solid,
width: 1.0,
),
borderRadius: BorderRadius.circular(20)),
child: Center(
child: Icon(
Icons.search,
color: Colors.black,
),
),
),
Container(
height: 65.0,
width: MediaQuery.of(context).size.width / 6,
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey,
style: BorderStyle.solid,
width: 1.0,
),
borderRadius: BorderRadius.circular(20)),
child: Center(
child: Icon(
Icons.shopping_cart,
color: Colors.black,
),
),
),
Container(
height: 65.0,
width: MediaQuery.of(context).size.width / 2,
decoration: BoxDecoration(
color: Color(0xff170F1F),
border: Border.all(
color: Colors.grey,
style: BorderStyle.solid,
width: 1.0,
),
borderRadius: BorderRadius.circular(20)),
child: Center(
child: Text(
'Checkout',
style: TextStyle(
fontSize: 18.0,
color: Colors.white,
fontFamily: 'Mont',
),
)),
),
],
),
],
),
),
],
),
);
}
Widget _buildFoodItem(String imgPath, String foodName, String price) {
return Padding(
padding: EdgeInsets.only(left: 10.0, right: 10.0, top: 10.0),
child: InkWell(
onTap: () {
Navigator.push( //Here is the Navigator.push()
context,
MaterialPageRoute(builder: (BuildContext context) {
return DetailsPage();
}),
);
},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
child: Row(
children: [
Hero(
tag: imgPath,
child: Image(
image: AssetImage(imgPath),
fit: BoxFit.cover,
height: 75.0,
width: 75.0,
),
),
SizedBox(width: 10.0),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
foodName,
style: TextStyle(
fontFamily: 'Mont',
fontSize: 17.0,
fontWeight: FontWeight.bold),
),
Text(
price,
style: TextStyle(
fontFamily: 'Mont',
fontSize: 15.0,
color: Colors.grey),
)
],
),
],
),
),
IconButton(
icon: Icon(Icons.add),
color: Colors.black,
onPressed: () {},
),
],
),
),
);
}
}
Navigator.push code is like this:
Navigator.push(
context,
MaterialPageRoute(builder: (BuildContext context) {
return DetailsPage();
}),
);
detailsPage.dart
import 'package:flutter/material.dart';
class DetailsPage extends StatefulWidget {
#override
_DetailsPageState createState() => _DetailsPageState();
}
class _DetailsPageState extends State<DetailsPage> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xFF7A9BEE),
appBar: AppBar(
leading: IconButton(
onPressed: () {
Navigator.of(context).pop();
},
icon: Icon(Icons.arrow_back_ios),
color: Colors.white,
),
backgroundColor: Colors.transparent,
elevation: 0.0,
title: Text(
'Details',
style: TextStyle(
fontFamily: 'Mont',
fontSize: 18.0,
color: Colors.white,
),
),
centerTitle: true,
actions: <Widget>[
IconButton(
icon: Icon(Icons.more_horiz),
onPressed: () {},
color: Colors.white,
),
],
),
);
}
}
Here is git Repository link: 1
i dont see the hero widget in the detailsPage.dart, when you set up a Hero widget in main and Navigate to detailsPage, you have to set up a hero widget to receive a hero transition from the main page, and because you have a listView in main you have to give a dynamic tag to each list item because each hero must have a tag associated with it so when it transfer to different layout it knows which hero to transit to it,
you already set up a hero tag in main page and you already give it a tag as tag: imgPath
tag is like an id for that hero, now you need to set the same tag (id) in the detailsPage,
please watch this to understand the logic Hero Flutter Widget
You should use Hero Widgets on both screens.
I couldn't find the Hero widget, nor the tag and not the image that you used on your first screen too (AssetImage(imgPath))
Try and parameterize using the propoer Hero specs.
Here you can find an good example and instructions: Flutter example

Why Flutter IconButton Animation Shows Under the Row

In my app, I setup a IconButton to render over a Row with a color background. Unfortunately, the ripple animation on button press renders under the Row (as shown in the screencast). How do i make the ripple show over the Row?
class Card extends StatelessWidget {
final Issue issue;
Color _bgColor;
Card({this.issue}) {
_bgColor = colorSwatch[issue.hashCode % colorSwatch.length];
}
#override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(top: 12, left: 18, right: 18),
padding: EdgeInsets.only(top: 8, bottom: 8),
decoration: new BoxDecoration(
color: _bgColor,
border: new Border.all(color: _bgColor),
borderRadius: BorderRadius.all(
Radius.circular(10.0)
),
),
child: Row(children: [
IconButton(
padding: EdgeInsets.only(right: 16),
icon: Icon(Icons.play_arrow, color: Colors.white, size: 48),
tooltip: 'Start ${issue.issueName}',
onPressed: () {},
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.only(bottom: 8),
child: Text(
issue.title,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
softWrap: true,
),
),
Text(
issue.issueName,
style: TextStyle(
color: Colors.white,
),
),
],
),
),
]));
}
}
The ripple is part of the Material effect. Wrap your IconButton with Material:
Material(
color: _bgColor,
child: IconButton(
padding: EdgeInsets.only(right: 16),
icon: Icon(Icons.play_arrow, color: Colors.white, size: 48),
tooltip: 'Start ${issue.issueName}',
onPressed: () {},
),
),
UPDATE
To be more specific to your goal, you can replace your Container with Material.
return Material(
color: _bgColor,
borderRadius: BorderRadius.all(Radius.circular(10.0)),
child: Container(
margin: EdgeInsets.only(top: 12, left: 18, right: 18),
padding: EdgeInsets.only(top: 8, bottom: 8),
backgroundBlendMode: BlendMode.multiply,
child: Row(
...
),
);
It looks like a bug in the Flutter Framework.
This occurs only with IconButton, no problem with FlatButton.
Possible workaround is to set BlendMode to multiply BlendMode.multiply.
try this:
Container(
decoration: BoxDecoration(
color: Colors.greenAccent[400],
backgroundBlendMode: BlendMode.multiply),
child: ListTile(
leading: IconButton(icon: Icon(Icons.play_arrow), onPressed: () {}),
title: Text("issue title"),
subtitle: Text("description"),
),
),
Update
issue on github
You can wrap your Row inside a InkWell, this will give you the touch ripples.
I have removed the background color of the container, had issues with it showing the ripple, as well as changed the text color to black.
#override
Widget build(BuildContext context) {
return Container(
height: 100,
margin: EdgeInsets.only(top: 12, left: 18, right: 18),
padding: EdgeInsets.only(top: 8, bottom: 8),
decoration: new BoxDecoration(
color: Colors.transparent,
border: new Border.all(color: Colors.orange),
borderRadius: BorderRadius.all(Radius.circular(10.0)),
),
child: InkWell(
// added here
onTap: () {},
child: Row(children: [
IconButton(
padding: EdgeInsets.only(right: 16),
icon: Icon(Icons.play_arrow, color: Colors.black, size: 48),
tooltip: 'Start issue',
onPressed: () {},
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.only(bottom: 8),
child: Text(
'issue.title',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
),
softWrap: true,
),
),
Text(
'issue.issueName',
style: TextStyle(
color: Colors.black,
),
),
],
),
),
]),
));
}
References
Add ripples
Ripple always takes on top of the material widgets. So if there is anything on top of the material widget you will see ripples under your widget.
Just wrap your IconButton with a Material widget with the material set to use the "transparency" type and it should work.
You can use the below generic widget for adding ripples to your widgets.
class AddRipple extends StatelessWidget {
final Widget child;
final Function onTap;
AddRipple({#required this.child, #required this.onTap});
#override
Widget build(BuildContext context) {
return Stack(
children: <Widget>[
child,
Positioned.fill(
child: new Material(
color: Colors.transparent,
child: new InkWell(
onTap: onTap,
))),
],
);
}
}
You can also take in a color in the constructor and user 'splashColor' property of the InkWell widget to set the splash color.