Flutter how to add a dialog screen over main screen like this - flutter

Hi all,
I would like to add a screen that slowly appears form the bottom or the screen and partially covers the main screen below. So you can still see the top part of the main screen. Does anyone know how to do this?
Thank you very much

for this you can use showModalBottomSheet method the simple example is
import 'package:flutter/material.dart';
void main() => runApp(const BottomSheetApp());
class BottomSheetApp extends StatelessWidget {
const BottomSheetApp({super.key});
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Bottom Sheet Sample')),
body: const BottomSheetExample(),
),
);
}
}
class BottomSheetExample extends StatelessWidget {
const BottomSheetExample({super.key});
#override
Widget build(BuildContext context) {
return Center(
child: ElevatedButton(
child: const Text('showModalBottomSheet'),
onPressed: () {
showModalBottomSheet<void>(
context: context,
builder: (BuildContext context) {
return Container(
height: 200,
color: Colors.amber,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const Text('Modal BottomSheet'),
ElevatedButton(
child: const Text('Close BottomSheet'),
onPressed: () => Navigator.pop(context),
),
],
),
),
);
},
);
},
),
);
}
}
you can read more about this method here

You can use showModalBottomSheet() same as below...
showModalBottomSheet<void>(
// context and builder are
// required properties in this widget
context: context,
builder: (BuildContext context) {
// we set up a container inside which
// we create center column and display text
// Returning SizedBox instead of a Container
return SizedBox(
height: MediaQuery.of(context).size.height * 0.6,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const <Widget>[
Text('HERE You'll add all your content'),
],
),
),
);
},
);
You can call above method in
initState() of screen or buttons onPressed or onTap.

As per your shared Image I have try something like that Using ModalBottomSheet
Your Button Widget
ElevatedButton(
child: const Text('Show Modal BottomSheet'),
onPressed: () {
showModalBottomSheet<void>(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(25.0)),
),
context: context,
builder: (BuildContext context) {
return modelSheet(context);
},
);
},
)
bottomSheet Widget:
modelSheet(BuildContext context) {
return Container(
padding: const EdgeInsets.all(12),
decoration: const BoxDecoration(
borderRadius: BorderRadius.vertical(top: Radius.circular(25.0)),
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Icon(
Icons.hourglass_empty_outlined,
color: Colors.red,
size: 40,
),
const SizedBox(
height: 10,
),
const Text(
'Beta version',
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.bold,
),
),
const SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Icon(
Icons.check,
color: Colors.red,
),
Text('better price')
],
),
const SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Icon(
Icons.check,
color: Colors.red,
),
Text('early access')
],
),
const SizedBox(
height: 20,
),
RichText(
text: const TextSpan(
text:
'Please mind that this is a beta version of the app. As a founding member you can get',
style: TextStyle(fontSize: 20, color: Colors.black),
children: <TextSpan>[
TextSpan(
text: '50% off',
style: TextStyle(fontWeight: FontWeight.bold)),
TextSpan(text: ' the price & early access. !'),
],
),
),
const SizedBox(
height: 20,
),
const Text(
'You can look forward to more teachers and practices very soon.'),
const SizedBox(
height: 20,
),
ElevatedButton(
onPressed: () => Navigator.pop(context),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
fixedSize: const Size(double.maxFinite, 50)),
child: const Text('Got it'),
),
],
),
),
);
}
Result Screen->

Related

How to update a field even if it is not inside the build Widget?

I have 2 variables that can be updated if I pressed a button. _tempQuan1 is not getting updated (immediately) since it is not in the build Widget. On the other hand, _tempQuan2 gets the updated for every button press. Is there a way so that I can get the _tempQuan1 to work same as _tempQuan2?
Note: I have tried to remove all other codes until I found out about the information above.
Edit: I have also tried to make it as a stateless widget and use Getx and make an observable variable but I still unable to do it.
import 'package:flutter/material.dart';
import 'package:awesome_dialog/awesome_dialog.dart';
class ShoppingWidget extends StatefulWidget {
State<StatefulWidget> createState() => ShoppingState();
}
class ShoppingState extends State<ShoppingWidget> {
int _tempQuan1 = 1;
int _tempQuan2 = 1;
#override
void initState() {
super.initState();
}
#override
void dispose() {
super.dispose();
}
showBuyPopup() async {
AwesomeDialog(
context: context,
dialogType: DialogType.NO_HEADER,
body: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: <Widget>[
Container(
width: 32.0,
height: 25.0,
child: Text(
_tempQuan1.toString(),
),
),
ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: Material(
child: InkWell(
splashColor: Theme.of(context).primaryColor,
onTap: () {
if (this.mounted) {
setState(() {
_tempQuan1++;
});
}
print('increase');
},
child: Container(
width: 35.0,
height: 32.0,
decoration: BoxDecoration(
color: Theme.of(context).primaryColorDark.withOpacity(0.9),
borderRadius: BorderRadius.circular(8.0),
),
child: Icon(
Icons.add,
color: Colors.white,
size: 18.0,
),
),
),
),
),
],
),
SizedBox(
height: 10.0,
),
],
),
),
buttonsTextStyle: Theme.of(context).textTheme.bodyText2,
showCloseIcon: false,
btnCancelOnPress: () {},
btnOkOnPress: () async {},
)..show();
}
#override
Widget build(BuildContext context) {
print('PATH: item card widget build');
return Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
children: <Widget>[
Text(
_tempQuan2.toString(),
),
ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: Material(
child: InkWell(
splashColor: Theme.of(context).primaryColor,
onTap: () {
if (this.mounted) {
setState(() {
_tempQuan2++;
});
}
print('increase');
},
child: Container(
width: 35.0,
height: 32.0,
decoration: BoxDecoration(
color: Theme.of(context).primaryColorDark.withOpacity(0.9),
borderRadius: BorderRadius.circular(8.0),
),
child: Icon(
Icons.add,
color: Colors.white,
size: 18.0,
),
),
),
),
),
],
),
Container(
child: ElevatedButton(
onPressed: () {
showBuyPopup();
},
child: Text(
'Button',
),
),
),
],
),
);
}
}
The easiest solution is to move the body of your dialog into it's own stateful widget.. ie something like
AwesomeDialog(
context: context,
body: MyAwesomeDialogBody(tempQuan: _tempQuan2),
).show()
And then have a stateful widget MyAwesomeDialogBody which basically does everything you had previously in the body.
You would also have to pass in some callback so the changes to tempQuan are communicated back to the parent widget..

Flutter - Quarter round Button

For my Flutter App I want that four buttons together are a circle. Here an Image of what i kinda want.
I don't know how to style the corners of a button in flutter.
In case of button 1 my idea would be to take the upper left corner and set the border radius and leave the other corners normal. With the other buttons I would do the same with the appropriated corners. To arrange my "pizza slices" i would use Colums and Rows.
I just don't know and couldn't figure out how to style only one corner.
Thanks for everyone in advance for helping.
Hi I do that with Grid View and "Clip R Rec t"
enter image description here
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(100),
child: Container(
height: 120,
width: 120,
child: GridView.count(
primary: false,
padding: const EdgeInsets.all(0),
crossAxisSpacing: 3,
mainAxisSpacing: 3,
crossAxisCount: 2,
children: [
ElevatedButton(
onPressed: () {},
child: Text("1", textAlign: TextAlign.right),
style: ElevatedButton.styleFrom(
primary: Colors.blueGrey,
),
),
ElevatedButton(
onPressed: () {},
child: Text("2", textAlign: TextAlign.center),
style: ElevatedButton.styleFrom(
primary: Colors.blueGrey,
),
),
ElevatedButton(
onPressed: () {},
child: Text("3", textAlign: TextAlign.center),
style: ElevatedButton.styleFrom(
primary: Colors.blueGrey,
),
),
ElevatedButton(
onPressed: () {},
child: Text("4", textAlign: TextAlign.center),
style: ElevatedButton.styleFrom(
primary: Colors.blueGrey,
),
),
],
),
),
),
),
),
);
}
}
and you can use Align Widget and put your numbers in align to you have a beautiful UI like this : enter image description here
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(100),
child: Container(
height: 120,
width: 120,
child: GridView.count(
primary: false,
padding: const EdgeInsets.all(0),
crossAxisSpacing: 3,
mainAxisSpacing: 3,
crossAxisCount: 2,
children: [
ElevatedButton(
onPressed: () {},
child: Align(
alignment: Alignment(0.5, 0),
child: Text("1", textAlign: TextAlign.center),
),
style: ElevatedButton.styleFrom(
primary: Colors.blueGrey,
),
),
ElevatedButton(
onPressed: () {},
child: Align(
alignment: Alignment(-0.5, 0),
child: Text("2", textAlign: TextAlign.center),
),
style: ElevatedButton.styleFrom(
primary: Colors.blueGrey,
),
),
ElevatedButton(
onPressed: () {},
child: Align(
alignment: Alignment(0.5, 0),
child: Text("3", textAlign: TextAlign.center),
),
style: ElevatedButton.styleFrom(
primary: Colors.blueGrey,
),
),
ElevatedButton(
onPressed: () {},
child: Align(
alignment: Alignment(-0.5, 0),
child: Text("4", textAlign: TextAlign.center),
),
style: ElevatedButton.styleFrom(
primary: Colors.blueGrey,
),
),
],
),
),
),
),
),
);
}
}
you can compare between images and code and If you liked my answer and it was useful, I will be happy for you to rate my answer.
Thank You.
One possible solution would be to create a Container with a fixed width and height. Then you set a background color and the border radius with BorderRadius.only for topLeft, topRight etc.
Now you only have to create a column with two rows containing your respective containers.
E.g.:
// pizza_button.dart
enum PizzaPosition { topLeft, topRight, bottomLeft, bottomRight }
class PizzaButton extends StatelessWidget {
final PizzaPosition pizzaPosition;
final _buttonSize = 60.0;
const PizzaButton({Key? key, required this.pizzaPosition}) : super(key: key);
BorderRadiusGeometry? _generateBorderRadius() {
switch (pizzaPosition) {
case PizzaPosition.topLeft:
return BorderRadius.only(
topLeft: Radius.circular(_buttonSize),
);
case PizzaPosition.topRight:
return BorderRadius.only(
topRight: Radius.circular(_buttonSize),
);
case PizzaPosition.bottomLeft:
return BorderRadius.only(
bottomLeft: Radius.circular(_buttonSize),
);
case PizzaPosition.bottomRight:
return BorderRadius.only(
bottomRight: Radius.circular(_buttonSize),
);
}
}
#override
Widget build(BuildContext context) {
return Container(
width: _buttonSize,
height: _buttonSize,
margin: EdgeInsets.all(1.0),
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: _generateBorderRadius(),
),
child: Text("1"),
);
}
}
And for the whole "pizza" an example widget would be
class Pizza extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Center(
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
PizzaButton(pizzaPosition: PizzaPosition.topLeft),
PizzaButton(pizzaPosition: PizzaPosition.topRight),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
PizzaButton(pizzaPosition: PizzaPosition.bottomLeft),
PizzaButton(pizzaPosition: PizzaPosition.bottomRight),
],
)
],
),
);
}
}
Now to have it work as buttons you should wrap the containers inside PizzaButton in GestureDetectors and specify your action onTap which can be hold as another property of PizzaButton for example.
you can do it inside a card like this
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('My App'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Card(
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(60.0),
),
child: SizedBox(
width: 120,
height: 120,
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: Row(
children: [
Expanded(
child: InkWell(
onTap: () {},
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text("1"),
)),
),
Expanded(
child: InkWell(
onTap: () {},
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text("2"),
)),
)
],
),
),
Expanded(
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: InkWell(
onTap: () {},
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text("1"),
)),
),
Expanded(
child: InkWell(
onTap: () {},
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text("2"),
)),
)
],
),
)
],
),
),
),
),
));
}
Thank you to everyone here!
I got an solution based of this Question:
[https://stackoverflow.com/questions/53138955/how-can-i-make-a-buttons-corner-only-rounded-on-the-top]
And based of the answer of #fusion
My solution looks like this:
import 'package:flutter/material.dart';
enum QuarterPosition { topLeft, topRight, bottomLeft, bottomRight }
class QuarterButton extends StatelessWidget {
const QuarterButton({Key? key, required this.position, this.size = 100, this.text = ""}) : super(key: key);
final QuarterPosition position;
final double size;
final String text;
BorderRadiusGeometry _generateBorderRadius() {
switch (position) {
case QuarterPosition.topLeft:
return BorderRadius.only(
topLeft: Radius.circular(size),
);
case QuarterPosition.topRight:
return BorderRadius.only(
topRight: Radius.circular(size),
);
case QuarterPosition.bottomLeft:
return BorderRadius.only(
bottomLeft: Radius.circular(size),
);
case QuarterPosition.bottomRight:
return BorderRadius.only(
bottomRight: Radius.circular(size),
);
}
}
#override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: () {},
child: Text(text, style: TextStyle(fontSize: 30, color: Colors.white)),
style: ElevatedButton.styleFrom(
primary: Colors.black54,
fixedSize: Size(size, size),
shape: RoundedRectangleBorder(
borderRadius: _generateBorderRadius(),
),
side: BorderSide(color: Colors.white)),
);
}
}
And I can use it now like that.
Column(
children: [
Row(
children: [
QuarterButton(position: QuarterPosition.topLeft, size: 100, text: "1"),
QuarterButton(position: QuarterPosition.topRight, size: 100, text: "2"),
],
),
Row(
children: [
QuarterButton(position: QuarterPosition.bottomLeft, size: 100, text: "3"),
QuarterButton(position: QuarterPosition.bottomRight, size: 100, text: "4"),
],
),
],
);
Thanks for all the quick answers. Great community! :)

How to change the Flutter TextButton height?

This is the output:
I try to make an app but when I use the TextButton, I get the space between two Buttons
I need one by one without space
If I use the Expanded Widget, ScrollChildView doesn't work
I try but I can't clear this stuff.
I try to make this type of TextButton.
Anyone know or have any idea about this?
import "package:flutter/material.dart";
import 'package:audioplayers/audio_cache.dart';
class Account extends StatefulWidget {
Account({Key key}) : super(key: key);
#override
_AccountState createState() => _AccountState();
}
class _AccountState extends State<Account> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: SingleChildScrollView(
child: Stack(
children: [
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
TextButton(
child: Container(
child: Text(
'One',
style: TextStyle(color: Colors.white, fontSize: 10),
),
),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(Colors.red),
),
onPressed: () {
final player = AudioCache();
player.play('note1.wav');
},
),
SizedBox(
height: 1,
),
TextButton(
child: Container(
child: Text(
'Two',
style: TextStyle(color: Colors.white, fontSize: 10),
),
),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(Colors.green),
),
onPressed: () {
final player = AudioCache();
player.play('note2.wav');
},
),
TextButton(
child: Container(
child: Text(
'Three',
style: TextStyle(color: Colors.white, fontSize: 10),
),
),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(Colors.blue),
),
onPressed: () {
final player = AudioCache();
player.play('note3.wav');
},
),
TextButton(
child: Container(
child: Text(
'Four',
style: TextStyle(color: Colors.white, fontSize: 10),
),
),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(Colors.grey),
),
onPressed: () {
final player = AudioCache();
player.play('note4.wav');
},
),
TextButton(
child: Container(
child: Text(
'Five',
style: TextStyle(color: Colors.white, fontSize: 10),
),
),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(Colors.purple),
),
onPressed: () {
final player = AudioCache();
player.play('note5.wav');
},
),
],
),
),
],
),
),
),
);
}
}
You just wrap your text button with the SizedBox and set height and width as follows:
SizedBox(
height: 30,
width: 150,
child: TextButton(...),
)
Full available height:
SizedBox(
height: double.infinity, // <-- match_parent
child: TextButton(...)
)
Specific height:
SizedBox(
height: 100, // <-- Your height
child: TextButton(...)
)
In Flutter 2.0, you can set the height of the TextButton directly without depending on other widgets by changing the ButtonStyle.fixedSize:
TextButton(
child: Text('Text Button'),
style: TextButton.styleFrom(fixedSize: Size.fromHeight(150)),
),
If you want to modify all TextButtons, put it in the ThemeData like below:
return MaterialApp(
theme: ThemeData(
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(fixedSize: Size.fromHeight(150)),
),
),
Live Demo
use the following to even add your preferred size as well
N/B: child sized box is the main child widget inside Padding widget
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(30.0),
child: SizedBox(
height: 60,
width: 200,
child: ElevatedButton.icon(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => RegistrationMenu()));
},
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(Colors.red.shade800),
),
icon: Icon(Icons.person_add_alt_1_rounded, size: 18),
label: Text("Register Users"),
),
),
),
],
),
Wrap the TextButton in an "Expanded" Widget.
Expanded(
child: TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.red,
padding: EdgeInsets.zero,
),
child: const Text(''),
onPressed: () {
playSound(1);
},
),
),
Another solution would be wrapping with ConstrainedBox and using minWidth & minHeight
properties.
ConstrainedBox(
constraints:BoxConstraints(
minHeight:80,
minWidth:200
),
child:TextButton(..)
)
You need to do two things
Determine text button height using
Sizedbox
Remove padding around text button using
TextStyle.StyleFrom()
SizedBox(
height: 24.0,
child: TextButton(
onPressed: () {},
child: Text('See more'),
style: TextButton.styleFrom(
padding: EdgeInsets.zero,
),
),
),
TextButton(
 onPressed: _submitOrder,
 child: Padding(
     padding: EdgeInsets.only(left: 20, right: 20),
     child: Text("Raise")),
 style: ButtonStyle(
   shape: MaterialStateProperty.all(
   const RoundedRectangleBorder(
   borderRadius: BorderRadius.all(Radius.circular(50)),
   side: BorderSide(color: Colors.green)))),
)
TextButton(
style: ButtonStyle(
tapTargetSize: MaterialTapTargetSize.shrinkWrap
),
child: Text(''),
);

How to create an admin UI left menu with Flutter [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm new to flutter but I have a curiosity. Considering the typical bootstrap admin UI that you can find online and the typical left menu, how would you recreate that with flutter? I'm particularly interested on a left menu that can be resized clicking on a button and on a sub-menu that can appear and disappear.
An example can be found here
Edit:
I want to be be clear about the effect I'm trying to reproduce as well. If you click the link relative to the example on the left you see a number of menu. For instance, clicking on Base you are going to see a vertical menu appearing and disappearing. I would like to know how to reproduce it as well.
Thanks
Thanks
I have tried to re-create the same design with some minor changes in Flutter. I have to enable flutter web support by following the instructions here:
Flutter Web
Regarding the left menu, I have used AnimatedSize widget to give the sliding drawer feel & placed it inside Row.
Please find the code below:
import 'package:flutter/material.dart';
final Color darkBlue = 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 StatefulWidget {
#override
_MyWidgetState createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget>
with SingleTickerProviderStateMixin {
final colors = <Color>[Colors.indigo, Colors.blue, Colors.orange, Colors.red];
double _size = 250.0;
bool _large = true;
void _updateSize() {
setState(() {
_size = _large ? 250.0 : 0.0;
_large = !_large;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Row(
children: [
AnimatedSize(
curve: Curves.easeIn,
vsync: this,
duration: Duration(seconds: 1),
child: LeftDrawer(size: _size)),
Expanded(
flex: 4,
child: Container(
child: Column(
children: [
Container(
color: Colors.white,
padding: const EdgeInsets.all(8),
child: Row(
children: [
IconButton(
icon: Icon(Icons.menu, color: Colors.black87),
onPressed: () {
_updateSize();
},
),
FlatButton(
child: Text(
'Dashboard',
style: const TextStyle(color: Colors.black87),
),
onPressed: () {},
),
FlatButton(
child: Text(
'User',
style: const TextStyle(color: Colors.black87),
),
onPressed: () {},
),
FlatButton(
child: Text(
'Settings',
style: const TextStyle(color: Colors.black87),
),
onPressed: () {},
),
const Spacer(),
IconButton(
icon: Icon(Icons.brightness_3, color: Colors.black87),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.notification_important,
color: Colors.black87),
onPressed: () {},
),
CircleAvatar(),
],
),
),
Container(
height: 1,
color: Colors.black12,
),
Card(
margin: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0),
),
child: Container(
color: Colors.white,
padding: const EdgeInsets.all(20),
child: Row(
children: [
Text(
'Home / Admin / Dashboard',
style: const TextStyle(color: Colors.black),
),
],
),
),
),
Expanded(
child: ListView(
children: [
Row(
children: [
_container(0),
_container(1),
_container(2),
_container(3),
],
),
Container(
height: 400,
color: Color(0xFFE7E7E7),
padding: const EdgeInsets.all(16),
child: Card(
color: Colors.white,
child: Container(
padding: const EdgeInsets.all(16),
child: Text(
'Traffic',
style: const TextStyle(color: Colors.black87),
),
),
),
),
],
),
),
],
),
),
),
],
),
);
}
Widget _container(int index) {
return Expanded(
child: Container(
padding: const EdgeInsets.all(20),
color: Color(0xFFE7E7E7),
child: Card(
color: Color(0xFFE7E7E7),
child: Container(
color: colors[index],
width: 250,
height: 140,
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: Text(
'9.823',
style: TextStyle(fontSize: 24),
)),
Icon(Icons.more_vert),
],
),
Text('Members online')
],
),
),
),
),
);
}
}
class LeftDrawer extends StatelessWidget {
const LeftDrawer({
Key key,
this.size,
}) : super(key: key);
final double size;
#override
Widget build(BuildContext context) {
return Expanded(
flex: 1,
child: Container(
width: size,
color: const Color(0xFF2C3C56),
child: ListView(
children: [
Container(
alignment: Alignment.center,
padding: const EdgeInsets.all(16),
color: Color(0xFF223047),
child: Text('CORE UI'),
),
_tile('Dashboard'),
Container(
padding: const EdgeInsets.only(left: 10),
margin: const EdgeInsets.only(top: 30),
child: Text('THEME',
style: TextStyle(
color: Colors.white54,
))),
_tile('Colors'),
_tile('Typography'),
_tile('Base'),
_tile('Buttons'),
],
),
),
);
}
Widget _tile(String label) {
return ListTile(
title: Text(label),
onTap: () {},
);
}
}
You can use the Drawer widget inside a Scaffold. If you want the navigation drawer to be able to resize according to the browser height and width you can use the responsive_scaffold package.

"Undefined name 'context'. Try correcting the name to one that is defined, or defining the name." Flutter

This is a snippet of my widgets.dart file where I defined a widget called see_all_cards and its only purpose is to show an extended list of all cards that I was initially displaying. It should just redirect to Trending.dart. That's my main goal here.
Widget see_all_cards(){
return Container(
child: FlatButton(
child: Text(
"See all (43)",
style: TextStyle(
color: Theme.of(context).accentColor, // error
),
),
onPressed: (){
Navigator.push(
context, // error
MaterialPageRoute(
builder: (BuildContext context){
return trending();
},
),
);
},
)
);
}
The following segment is my main page. I've called SlowlyApp from void main.
class SlowlyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'SlowlyApp',
home: Scaffold(
appBar: AppBar(
title: Text('Search',
style: TextStyle(
color: Color.fromRGBO(0,0,0,1),
),
),
backgroundColor: Color.fromRGBO(225,225,0,1),
actions: <Widget>[
IconButton(
icon:
Icon(Icons.search),
onPressed: (){
showSearch(context: context, delegate: data_search());
}
),
],
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
smallgap(),
current_cards_heading(),
current_cards(),
see_all_cards(),
smallgap(),
],
),
),
);
}
}
see_all_cards should expect context as parameter. You only have context in your main widget's build method
Widget see_all_cards(BuildContext context){
return Container(
child: FlatButton(
child: Text(
"See all (43)",
style: TextStyle(
color: Theme.of(context).accentColor, // error
),
),
onPressed: (){
Navigator.push(
context, // error
MaterialPageRoute(
builder: (BuildContext context){
return trending();
},
),
);
},
)
);
}
And then you can call passing the context.
class SlowlyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'SlowlyApp',
home: Scaffold(
appBar: AppBar(
title: Text('Search',
style: TextStyle(
color: Color.fromRGBO(0,0,0,1),
),
),
backgroundColor: Color.fromRGBO(225,225,0,1),
actions: <Widget>[
IconButton(
icon:
Icon(Icons.search),
onPressed: (){
showSearch(context: context, delegate: data_search());
}
),
],
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
smallgap(),
current_cards_heading(),
current_cards(),
see_all_cards(context),
smallgap(),
],
),
),
);
}
}
I also get this error to solve this way
it's the main file container called my widgets _buildFoodItem define context with parameters
Container(
height: MediaQuery.of(context).size.height - 185.0,
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(75.0),
),
),
child: ListView(
primary: true,
padding: const EdgeInsets.only(left: 25.0, right: 20.0),
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 45.0),
child: Container(
height: MediaQuery.of(context).size.height - 300.0,
child: ListView(children: [
_buildFoodItem(context, 'assets/images/plate1.png',
'Slazmon bowl', '₹ 150:00'),
_buildFoodItem(context, 'assets/images/plate2.png',
'Spring bowl', '₹ 120:00'),
_buildFoodItem(context, 'assets/images/plate3.png',
'Chikz bowl', '₹ 100:00'),
_buildFoodItem(context, 'assets/images/plate4.png',
'Berry Bowl', '₹ 199:00'),
_buildFoodItem(context, 'assets/images/plate5.png',
'Greezy bowl', '₹ 170:00'),
]),
),
)
],
),
),
this is my widget _buildFoodItem check the context
Widget _buildFoodItem(
BuildContext context, String imgPath, String foodName, String price) {
return Padding(padding: const EdgeInsets.only(
top: 10.0, left: 10.0, right: 10.0),
child: InkWell(
onTap: () {
Navigator.push(
context,
(MaterialPageRoute(
builder: (context) => FoodDetailsPage(
heroTag: imgPath,
foodName: foodName,
foodPrice: price,
),
)));
},
))
}
)