I want to make a set of buttons with the ripple effect, elevation and shape like a FAB button. I read that I can only use one FAB button per screen, so I need to create my owns instead of using a set of FAB buttons.
How can I achieve the effect? It's possible to modify the FAB code to this?
So if you want the fabs in a vertical order wrap them in a Column like this
class RandomFabScreen extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
FloatingActionButton(
child: Icon(Icons.home, color: Colors.white,),
onPressed: (){},
backgroundColor: Colors.cyan,
),
SizedBox(height: 10,),
FloatingActionButton(
child: Icon(Icons.playlist_play, color: Colors.white,),
onPressed: (){},
backgroundColor: Colors.red,
),
SizedBox(height: 10,),
FloatingActionButton(
child: Icon(Icons.person, color: Colors.white,),
backgroundColor: Colors.yellow,
onPressed: (){},
),
SizedBox(height: 10,),
FloatingActionButton(
child: Icon(Icons.warning, color: Colors.white,),
onPressed: (){},
backgroundColor: Colors.blue,
),
],
),
);
}
}
The output:
And if you want them in the horizontal order, wrap them in a Row
like this
class RandomFabScreen extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
FloatingActionButton(
child: Icon(Icons.home, color: Colors.white,),
onPressed: (){},
backgroundColor: Colors.cyan,
),
SizedBox(width: 10,),
FloatingActionButton(
child: Icon(Icons.playlist_play, color: Colors.white,),
onPressed: (){},
backgroundColor: Colors.red,
),
SizedBox(width: 10,),
FloatingActionButton(
child: Icon(Icons.person, color: Colors.white,),
backgroundColor: Colors.yellow,
onPressed: (){},
),
SizedBox(width: 10,),
FloatingActionButton(
child: Icon(Icons.warning, color: Colors.white,),
onPressed: (){},
backgroundColor: Colors.blue,
),
],
),
);
}
}
The output:
You can use Row to wrap FloatingActionButton
code snippet
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
FloatingActionButton(
onPressed: () {
print("click 1");
},
child: Icon(Icons.navigation),
backgroundColor: Colors.green,
),
FloatingActionButton(
onPressed: () {
print("click 2");
},
child: Icon(Icons.event),
backgroundColor: Colors.red,
),
FloatingActionButton(
onPressed: () {
print("click 3");
},
child: Icon(Icons.gradient),
backgroundColor: Colors.yellow,
),
FloatingActionButton(
onPressed: () {
print("click 4");
},
child: Icon(Icons.album),
backgroundColor: Colors.blue,
),
]),
working demo
full code
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
FloatingActionButton(
onPressed: () {
print("click 1");
},
child: Icon(Icons.navigation),
backgroundColor: Colors.green,
),
FloatingActionButton(
onPressed: () {
print("click 2");
},
child: Icon(Icons.event),
backgroundColor: Colors.red,
),
FloatingActionButton(
onPressed: () {
print("click 3");
},
child: Icon(Icons.gradient),
backgroundColor: Colors.yellow,
),
FloatingActionButton(
onPressed: () {
print("click 4");
},
child: Icon(Icons.album),
backgroundColor: Colors.blue,
),
]),
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
Related
I'm building a motivational app.
I want the app to run as soon as people turn on their phones and unlock the lock screen.
I tried using auto_start_flutter that I learned through Googleing.
import 'dart:async';
import 'dart:convert';
// import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'package:share_plus/share_plus.dart';
import 'package:app/count_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'package:auto_start_flutter/auto_start_flutter.dart';
import './main.dart';
class HomePage extends StatefulWidget {
HomePage({Key? key}) : super(key: key);
#override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
final String androidTestId = 'ca-app-pub-3940256099942544/6300978111';
late CountPage _countPage;
// BannerAd? banner;
#override
void initState() {
super.initState();
initAutoStart();
// banner = BannerAd(
// listener: AdManagerBannerAdListener(),
// size: AdSize.banner,
// adUnitId: androidTestId,
// request: AdRequest(),//..load();
}
Future<void> initAutoStart() async {
try {
//check auto-start availability.
var test = await (isAutoStartAvailable as FutureOr<bool>);
print(test);
//if available then navigate to auto-start setting page.
if (test) await getAutoStartPermission();
} on PlatformException catch (e) {
print(e);
}
if (!mounted) return;
}
#override
Widget build(BuildContext context) {
_countPage = Provider.of<CountPage>(context, listen: true);
List list = jsonDecode(_countPage.arrayText);
bool toggle = false;
return Scaffold(
appBar: AppBar(
backgroundColor: _countPage.selection,
title: Text('철학 한 스푼'),
centerTitle: true, // 중앙 정렬
elevation: 0.0,
),
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
UserAccountsDrawerHeader(
// currentAccountPicture: CircleAvatar(
// backgroundImage: AssetImage('캡처.png'), // 앱 아이콘 들어갈자리
// backgroundColor: Colors.white,
// ),
accountName: Text('철학 한 스푼'),
accountEmail: Text("개발자 이메일: kaingsik13#naver.com"),
decoration: BoxDecoration(
color: _countPage.selection,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(40.0),
bottomRight: Radius.circular(40.0),
)),
),
ListTile(
leading: Icon(
Icons.home,
color: Colors.grey[850],
),
title: Text('메인 화면'),
onTap: () {
print('메인 화면 확인');
},
),
ListTile(
leading: Icon(
Icons.settings,
color: Colors.grey[850],
),
title: Text('설정'),
onTap: () {
Navigator.push(context,
MaterialPageRoute(builder: (BuildContext context) {
return Option_page();
}));
},
),
ListTile(
leading: Icon(
Icons.question_answer,
color: Colors.grey[850],
),
title: Text('리뷰 쓰기'),
onTap: () {
print('리뷰 화면 확인');
},
),
ListTile(
leading: Icon(
Icons.question_answer,
color: Colors.grey[850],
),
title: Text('후원 하기(광고 제거)'),
onTap: () {
print('후원 화면 확인');
},
),
],
),
),
body: Container(
color: Colors.white,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Center(
child: IconButton(
onPressed: () {
_countPage.page_down();
},
icon: Icon(Icons.chevron_left),
),
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: Container(
alignment: Alignment(0.0, 0.0),
color: Colors.white,
child: Text(
list[_countPage.page]["message"],
style: TextStyle(
fontSize: _countPage.font,
fontFamily: 'snow',
),
textAlign: _countPage.align,
),
),
),
Container(
height: 40,
width: 300,
color: Colors.white,
child: Center(
child: Text(
list[_countPage.page]["author"],
style: TextStyle(fontSize: 20, color: Colors.black),
))),
Container(
child: AnimatedOpacity(
opacity: _countPage.visible ? 1.0 : 0.0,
duration: Duration(milliseconds: 500),
child: Container(
height: 50,
width: 70,
color: Colors.black38,
child: Center(
child: Text("복사 확인",
style: TextStyle(
fontSize: 15, color: Colors.white)))),
),
),
],
),
),
Center(
child: IconButton(
onPressed: () {
_countPage.page_up();
},
icon: Icon(Icons.chevron_right)))
],
),
),
bottomNavigationBar: BottomAppBar(
color: _countPage.selection,
child: Container(
height: 150,
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Center(
child: IconButton(
onPressed: () {
_countPage.copy_on();
Clipboard.setData(ClipboardData(
text: list[_countPage.page]["message"]));
Future.delayed(Duration(milliseconds: 800), () {
_countPage.copy_on();
});
},
icon: Icon(Icons.content_copy))),
Center(
child: IconButton(
onPressed: () {
Share.share(list[_countPage.page]["message"]);
},
icon: Icon(Icons.share))),
],
),
Container(
height: 100,
color: Colors.green[50],
),
],
),
),
),
);
}
}
I extracted Android appk and tested it with my phone, but the app doesn't run after the lock screen.
I want my app to run as soon as I unlock the lock screen and come out.
iam new to flutter and i would like to add a text under a button, but i cant seems to do it, so far here's my result
..
i use two Rows for the button and the text,
as you guys can see the text isnt align really well, i tried using ElevatedButton but the text is beside the button not below it.
this is my code so far:
import 'package:flutter/material.dart';
import 'package:get/get_navigation/get_navigation.dart';
import 'package:medreminder/NewsArticle/news_home.dart';
import 'Reminder/ui/home_reminder.dart';
import 'Reminder/ui/widgets/button.dart';
import 'package:medreminder/main_reminder.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 MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text('Medicine Reminder App'),
),
body: Column(
children: [
Stack(
children: [
Image.asset(
'images/MenuImg.jpg',
width: 600,
height: 170,
fit: BoxFit.cover,
),
],
),
const SizedBox(height: 10.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
IconButton(
icon: Image.asset('images/reminder.png'),
iconSize: 50,
onPressed: () {
Navigator.of(context, rootNavigator: true).push(
MaterialPageRoute(builder: (context) => const ReminderHomePage()),
);
},
),
IconButton(
icon: Image.asset('images/news.png'),
iconSize: 50,
onPressed: () {},
),
IconButton(
icon: Image.asset('images/recipe.png'),
iconSize: 50,
onPressed: () {},
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text("Reminder"),
Text("News"),
Text("Recipe")
],
)
],
),
),
);
}
}
if anyone know how to do it, please help. it will mean so much to me. thank you
try to put each iconButton inside a Column with its Text widget, try this code:
import 'package:flutter/material.dart';
import 'package:get/get_navigation/get_navigation.dart';
import 'package:medreminder/NewsArticle/news_home.dart';
import 'Reminder/ui/home_reminder.dart';
import 'Reminder/ui/widgets/button.dart';
import 'package:medreminder/main_reminder.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 MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text('Medicine Reminder App'),
),
body: Column(
children: [
Stack(
children: [
Image.asset(
'images/MenuImg.jpg',
width: 600,
height: 170,
fit: BoxFit.cover,
),
],
),
const SizedBox(height: 10.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Column(
children: [
IconButton(
icon: Image.asset('images/reminder.png'),
iconSize: 50,
onPressed: () {
Navigator.of(context, rootNavigator: true).push(
MaterialPageRoute(builder: (context) => const ReminderHomePage()),
);
},
),
Text("Reminder")
],
),
Column(
children: [
IconButton(
icon: Image.asset('images/news.png'),
iconSize: 50,
onPressed: () {},
),
Text("News")
],
),
Column(
children: [
IconButton(
icon: Image.asset('images/recipe.png'),
iconSize: 50,
onPressed: () {},
),
Text("Recipe")
],
),
],
),
// Row(
// mainAxisAlignment: MainAxisAlignment.,
// children: [, , ],
// )
],
),
),
);
}
}
You can adjust Layout by using Row and Column
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Column(
children: [
const SizedBox(height: 10.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_showButton('assets/images/image1.jpg', 'Reminder'),
_showButton('assets/images/image2.jpg', 'News'),
_showButton('assets/images/image2.jpg', 'Recipe'),
],
),
],
),
),
);
}
_showButton(String imagePath, String text) {
return Column(
children: [
IconButton(
icon: Image.asset(imagePath),
iconSize: 50,
onPressed: () {
// Navigator.of(context, rootNavigator: true).push(
// MaterialPageRoute(builder: (context) => const ReminderHomePage()),
// );
},
),
Text(
text,
textAlign: TextAlign.center,
)
],
);
}
if u want to change the colour of the text button u can, its just commented out for you
import 'package:flutter/material.dart';
void main() {
// debugPaintSizeEnabled = true;
runApp(const HomePage());
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text('Medicine Reminder App'),
),
body: Column(
children: [
Stack(
children: [
Image.asset(
'images/MenuImg.jpg',
width: 600,
height: 170,
fit: BoxFit.cover,
),
],
),
const SizedBox(height: 10.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Column(
children: [
IconButton(
icon: Image.asset('images/reminder.png'),
iconSize: 50,
onPressed: () {
// Navigator.of(context, rootNavigator: true).push(
// MaterialPageRoute(
// builder: (context) => const ReminderHomePage()),
// );
},
),
TextButton(
onPressed: () => print('reminder'),
child: Text(
'Reminder',
//style: TextStyle(color: Colors.black),
))
],
),
Column(
children: [
IconButton(
icon: Image.asset('images/news.png'),
iconSize: 50,
onPressed: () {},
),
TextButton(
onPressed: () => print('News'),
child: Text(
'News',
// style: TextStyle(color: Colors.black),
))
],
),
Column(
children: [
IconButton(
icon: Image.asset('images/recipe.png'),
iconSize: 50,
onPressed: () {},
),
TextButton(
onPressed: () => print('Recipe'),
child: Text(
'Recipe',
style: TextStyle(color: Colors.black),
))
],
),
],
),
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceAround,
// children: [Text("Reminder"), Text("News"), Text("Recipe")],
// )
],
),
),
);
}
}
Try below code hope its helpful to you, I have try it two ways Using Column Widget and Gridview.builder(). Just replace my images with your image
1. Using Column Widget
Padding(
padding: const EdgeInsets.all(10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: const [
ImageRow(
imageUrl:
'https://cdn.iconscout.com/icon/free/png-256/reminder-1605670-1361019.png',
imageName: 'Reminder',
),
ImageRow(
imageUrl: 'https://cdn-icons-png.flaticon.com/512/21/21601.png',
imageName: 'News',
),
ImageRow(
imageUrl:
'https://cdn-icons-png.flaticon.com/512/1041/1041373.png',
imageName: 'Recipe',
),
],
),
),
ImageRow Class:
class ImageRow extends StatelessWidget {
const ImageRow({
Key? key,
required this.imageName,
required this.imageUrl,
}) : super(key: key);
final String imageUrl;
final String imageName;
#override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Image.network(
imageUrl,
height: 50,
),
const SizedBox(
height: 5,
),
Text(imageName),
],
);
}
}
2. Using Gridview.builder()
Declare List on your imageName and imageUrl
List medicineInfo = [
{
'imageUrl':
'https://cdn.iconscout.com/icon/free/png-256/reminder-1605670-1361019.png',
'imageName': 'Reminder',
},
{
'imageUrl': 'https://cdn-icons-png.flaticon.com/512/21/21601.png',
'imageName': 'News',
},
{
'imageUrl': 'https://cdn-icons-png.flaticon.com/512/1041/1041373.png',
'imageName': 'Recipe',
},
];
GridView Widget:
Padding(
padding: const EdgeInsets.all(20),
child: GridView.builder(
shrinkWrap: true,
itemCount: medicineInfo.length,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
crossAxisSpacing: 20,
),
itemBuilder: (context, index) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Image.network(
medicineInfo[index]['imageUrl'],
height: 50,
),
const SizedBox(
height: 5,
),
Text(
medicineInfo[index]['imageName'],
),
],
);
},
),
),
Result Screen->
I currently am new in Flutter and is looking for help for a feature I'm trying to implement. I have too many information in my drawer currently so I am trying to put tabs inside the drawer so people can access different kinds of information inside the drawer. I photoshopped a picture to show the idea that I have in my head. Drawer with Tab Pictures shown here. So far, I've tried the DefaultTabController but couldn't get it to work so if anyone has any other ideas or a different way of approaching it I would be really grateful.
Thanks in advance!
You can copy paste run full code below
You can wrap DefaultTabController with Drawer
code snippet
return Scaffold(
...
drawer: Drawer(
child: DefaultTabController(
length: 3,
child: Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
DrawerHeader(
child: Text('Drawer Header'),
),
Container(
height: 50,
color: Colors.black12,
child: TabBar(
labelColor: Colors.deepOrange,
unselectedLabelColor: Colors.white,
tabs: [
Tab(text: "First"),
Tab(text: "Second"),
Tab(text: "Third"),
]),
),
Expanded(
child: Container(
color: Colors.green,
child: TabBarView(children: [
Container(
child: Text("First Body"),
),
Container(
child: Text("Second Body"),
),
Container(
child: Text("Third Body"),
),
]),
),
),
],
),
),
),
working demo
full code
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
drawer: Drawer(
child: DefaultTabController(
length: 3,
child: Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
DrawerHeader(
child: Text('Drawer Header'),
),
Container(
height: 50,
color: Colors.black12,
child: TabBar(
labelColor: Colors.deepOrange,
unselectedLabelColor: Colors.white,
tabs: [
Tab(text: "First"),
Tab(text: "Second"),
Tab(text: "Third"),
]),
),
Expanded(
child: Container(
color: Colors.green,
child: TabBarView(children: [
Container(
child: Text("First Body"),
),
Container(
child: Text("Second Body"),
),
Container(
child: Text("Third Body"),
),
]),
),
),
],
),
),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
I am developing an app with a dropdown. Below is my code. I have removed the UI design code to isolate the dropdown section itself.
class ShoppingCartUIState extends State<ShoppingCartUI> {
final _formKey = GlobalKey<FormState>();
String _checkoutDropdownValue=null;
//**UI design Code Removed**//
_showCheckoutPopup() {
String date=DateTime.now().toString();
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0)), //this right here
child: Container(
height: MediaQuery.of(context).size.height/3,
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Container(
margin: EdgeInsets.all(10),
child: Text(
"What is Your Required Delivery Date?",
style: Theme.of(context).textTheme.subtitle,
),)
],
),
Row(
children: <Widget>[
IconButton(
icon: Icon(Icons.calendar_today),
color: Colors.green,
onPressed: () {
date = "111";
},
),
Text(date)
],
),
Row(
children: <Widget>[
Container(
margin: EdgeInsets.only(top:20, left:10),
child: Text(
"What is your Airport of delivery?",
style: Theme.of(context).textTheme.subtitle,
),)
],
),
Row(
children: <Widget>[
Container(
margin: EdgeInsets.only(top:5, left:10),
child: DropdownButton(
hint: Text(
"Please Select ",
style: TextStyle(
fontSize: 14,
),
),
items: <String>[
'Skinless Boneless, Full Loins',
'brown',
'silver'
].map((data) {
return DropdownMenuItem(
child: new Text(data,
style: Theme.of(context).textTheme.body1),
value: data,
);
}).toList(),
onChanged: (String newValue) {
setState(() {
_checkoutDropdownValue = newValue;
print(newValue);
});
},
value: _checkoutDropdownValue),
)
],
),
],
),
));
}
#override
void initState() {
// TODO: implement initState
super.initState();
}
}
The issue is when I change the dropdown item, the new value never get selected. The previously selected value is always displayed. However since i am using a print when dropdown is done, I can see the item has changed.
How can I solved this issue?
Wrap your Dialog widget with StatefulBuilder to rebuild the dialog.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyPage(), //TODO: Add Scaffold
);
}
}
class MyPage extends StatefulWidget {
#override
_MyPageState createState() => _MyPageState();
}
class _MyPageState extends State<MyPage> {
String date = "";
String _checkoutDropdownValue;
_showCheckoutPopup() {
return StatefulBuilder(
builder: (context, setState){
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
), //this r// ight here
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
margin: EdgeInsets.all(10),
alignment: Alignment.centerLeft,
child: Text(
"What is Your Required Delivery Date?",
style: Theme.of(context).textTheme.subtitle,
),
),
Row(
children: <Widget>[
IconButton(
icon: Icon(Icons.calendar_today),
color: Colors.green,
onPressed: () {
setState(() {
date = "111";
});
},
),
Text(date)
],
),
Container(
margin: EdgeInsets.only(top: 20, left: 10),
alignment: Alignment.centerLeft,
child: Text(
"What is your Airport of delivery?",
style: Theme.of(context).textTheme.subtitle,
),
),
Row(
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 5, left: 10),
child: DropdownButton<String>(
hint: Text(
"Please Select ",
style: TextStyle(
fontSize: 14,
),
),
items: <String>[
'Skinless Boneless, Full Loins',
'brown',
'silver'
].map((data) {
return DropdownMenuItem(
child: new Text(data,
style: Theme.of(context).textTheme.body1),
value: data,
);
}).toList(),
onChanged: (String newValue) {
setState(() {
_checkoutDropdownValue = newValue;
});
},
value: _checkoutDropdownValue,
),
)
],
),
],
),
),
);
},
);
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: RaisedButton(
child: Text("Click Here"),
onPressed: () {
showDialog(
context: context,
builder: (context) => _showCheckoutPopup(),
);
},
),
),
);
}
}
can you change your onPressed to print(_checkoutDropdownValue); instead of print(newValue); that way we can see if there is a problem with the assignment
I am using bottom app bar for bottomnavigation in flutter. when tapped on one of the tab in the bottom app bar, i would still want the bottom app bar and app bar to remain as it is in it's fixed position but only the body content changes based on what is tapped.
I have tried to use push() method but it gives me a new page instead with a back button.
Navigation_tabs.dart:
import 'package:flutter/material.dart';
class NavigationTabs extends StatelessWidget {
#override
Widget build(BuildContext context) {
return new Scaffold(
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.add),
onPressed: () {},
),
appBar: AppBar(
title: Text('Dashboard'),
),
bottomNavigationBar: BottomAppBar(
shape: CircularNotchedRectangle(),
notchMargin: 4.0,
child: new Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
icon: Icon(
Icons.home,
color: Colors.cyan[700],
),
onPressed: () {},
),
new Container(
padding: EdgeInsets.only(left: 20),
child: IconButton(
icon: Icon(
Icons.list,
color: Colors.cyan[700],
),
onPressed: () => Navigator.pushNamed(context, '/login'),
)),
new Container(
padding: EdgeInsets.only(left: 120),
child: IconButton(
icon: Icon(
Icons.explore,
color: Colors.cyan[700],
),
onPressed: () {},
)),
new Container(
height: 22.0,
child: new RawMaterialButton(
onPressed: () {},
child: new Icon(
Icons.person,
color: Colors.white,
size: 20.0,
),
shape: new CircleBorder(),
elevation: 1.0,
fillColor: Colors.cyan[700],
))
],
),
));
}
}
I want to be able to only make the page content change without a back button instead of going to a completely new page when one of the tabs is pressed.
You can use a BottomNavigationBarItem instead of creating buttons and use the ontap of the bottomNavigationBar.
class _MyHomePageState extends State<MyHomePage> {
int _index = 0;
final List<Widget> _children = [
Center(child: Text("First Page"),),
Center(child: Text("Second Page"),),
Center(child: Text("Third Page"),)
];
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Bottom Navigation"),
),
body: Center(
child: (_children[_index ]),
),
bottomNavigationBar: BottomNavigationBar(
onTap: onTabTapped,
currentIndex: _currentIndex,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.looks_one),
title: Text('First'),
),
BottomNavigationBarItem(
icon: Icon(Icons.looks_two),
title: Text('Second'),
),
BottomNavigationBarItem(
icon: Icon(Icons.looks_3),
title: Text('Third'),
)
],
),
);
}
void onTabTapped(int index) {
setState(() {
_index = index;
});
}
}
For more detailed explanation:
Flutter documentation