Flutter - Button Group style and position - flutter

I am trying to create something like the attached image. I got this far ...
Expanded(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(32),
topRight: Radius.circular(32),
),
),
child: ButtonTheme(
child: ButtonBar(
alignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
onPressed: () => print('hi'),
child: Text('Referals'),
color: Color(0xff2FBBF0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(15.0),
topLeft: Radius.circular(15.0)),
),
),
RaisedButton(
onPressed: () => print('hii'),
child: Text('Stats'),
color: Color(0xff2FBBF0),
),
RaisedButton(
onPressed: () => print('hiii'),
child: Text('Edit Profile'),
color: Color(0xff2FBBF0),
// color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(15.0),
topRight: Radius.circular(15.0)),
),
),
],
),
),
),
),
But I don't really feel like it will look like the image.
I would also like the button group to be at the top of the Container. Now they're in the absolute center. Just like they would be if wrapped in a Center widget.

Here's the complete code. I have just used Container and Row because I find it more suitable and easy to achieve without any headache. :P
If you want with RaisedButton, figure it out.
Source:
import 'package:flutter/material.dart';
class Demo extends StatefulWidget {
#override
_DemoState createState() => new _DemoState();
}
class _DemoState extends State<Demo> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("DEMO")),
body: Padding( // used padding just for demo purpose to separate from the appbar and the main content
padding: EdgeInsets.all(10),
child: Container(
alignment: Alignment.topCenter,
child: Container(
height: 60,
padding: EdgeInsets.all(3.5),
width: MediaQuery.of(context).size.width * 0.9,
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.all(Radius.circular(15)),
),
child: Row(
children: <Widget>[
Expanded(
child: InkWell(
onTap: () {},
child: Container(
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(12),
topLeft: Radius.circular(12))),
child: Text("Referrals",
style: TextStyle(
color: Colors.blue,
fontSize: 17,
)),
))),
Expanded(
child: InkWell(
onTap: () {},
child: Container(
alignment: Alignment.center,
child: Text("Stats",
style: TextStyle(
color: Colors.white, fontSize: 17)),
))),
Padding(
padding: EdgeInsets.symmetric(vertical: 5),
child: Container(color: Colors.white, width: 2)),
Expanded(
child: InkWell(
onTap: () {},
child: Container(
alignment: Alignment.center,
child: Text("Edit Profile",
style: TextStyle(
color: Colors.white, fontSize: 17)),
)))
],
)),
)));
}
}
Output Screenshot:

Check my ButtonGroup widget that I created
import 'package:flutter/material.dart';
class ButtonGroup extends StatelessWidget {
static const double _radius = 10.0;
static const double _outerPadding = 2.0;
final int current;
final List<String> titles;
final ValueChanged<int> onTab;
final Color color;
final Color secondaryColor;
const ButtonGroup({
Key key,
this.titles,
this.onTab,
int current,
Color color,
Color secondaryColor,
}) : assert(titles != null),
current = current ?? 0,
color = color ?? Colors.blue,
secondaryColor = secondaryColor ?? Colors.white,
super(key: key);
#override
Widget build(BuildContext context) {
return Material(
color: color,
borderRadius: BorderRadius.circular(_radius),
child: Padding(
padding: const EdgeInsets.all(_outerPadding),
child: ClipRRect(
borderRadius: BorderRadius.circular(_radius - _outerPadding),
child: IntrinsicHeight(
child: Row(
mainAxisSize: MainAxisSize.min,
children: _buttonList(),
),
),
),
),
);
}
List<Widget> _buttonList() {
final buttons = <Widget>[];
for (int i = 0; i < titles.length; i++) {
buttons.add(_button(titles[i], i));
buttons.add(
VerticalDivider(
width: 1.0,
color: (i == current || i + 1 == current) ? color : secondaryColor,
thickness: 1.5,
indent: 5.0,
endIndent: 5.0,
),
);
}
buttons.removeLast();
return buttons;
}
Widget _button(String title, int index) {
if (index == this.current)
return _activeButton(title);
else
return _inActiveButton(title, index);
}
Widget _activeButton(String title) => FlatButton(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
disabledColor: secondaryColor,
disabledTextColor: color,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
),
child: Text(title),
onPressed: null,
);
Widget _inActiveButton(String title, int index) => FlatButton(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
color: Colors.transparent,
textColor: Colors.white,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
),
child: Text(title),
onPressed: () {
if (onTab != null) onTab(index);
},
);
}
You can use it like this
ButtonGroup(
titles: ["Button1", "Button2", "Button3"],
current: index,
color: Colors.blue,
secondaryColor: Colors.white,
onTab: (selected) {
setState(() {
index = selected;
});
},
)
Example:
import 'package:flutter/material.dart';
import 'package:flutter_app_test2/btn_grp.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: MainPage(),
);
}
}
class MainPage extends StatefulWidget {
#override
_MainPageState createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
int current = 0;
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ButtonGroup(
titles: ["Button1", "Button2", "Button3", "Button3"],
current: current,
onTab: (selected) {
print(selected);
setState(() {
current = selected;
});
},
),
),
);
}
}

try adding following in all RaisedButton widgets:
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
and buttonPadding: EdgeInsets.all(1), in ButtonBar
Source: https://api.flutter.dev/flutter/material/MaterialTapTargetSize-class.html

Related

How to implemented overlapped card with animation in flutter?

I'm trying to implement overlapped card with animation like below video which I have mentioned. I'm going to explain what I want to achieve, Look if I choose a card then that particular card should be expand and rest of the cards will be shrink toward the below but I could not able to do because, I'm so dumb in animation stuff,
Please look at this expected video :
video
CODE:
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../../../Utility/colorsScheme.dart';
import 'dart:math' as math;
class SubscriptionPlansScreen extends StatelessWidget {
const SubscriptionPlansScreen({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
elevation: 1,
backgroundColor: Colors.white,
title: Text(
"Subscription Plans",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w500,
fontSize: ScreenUtil().setSp(20),
),
),
centerTitle: true,
automaticallyImplyLeading: false,
leading: IconButton(
onPressed: () {
Navigator.of(context).pop();
},
icon: Icon(
Icons.arrow_back_ios_rounded,
color: Colors.black,
)),
),
body: LinearOverlappedStack());
}
}
class LinearOverlappedStack extends StatelessWidget {
final double size;
LinearOverlappedStack({Key? key, this.size = 50}) : super(key: key);
List<String> plans = [
"Premium",
"Gold (Monthly plan)",
"Silver (Monthly plan)",
"Bronze (Monthly plan)"
];
#override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(
top: 25.0,
),
child: Stack(
alignment: AlignmentDirectional.topCenter,
children: [...getListPosition(context)]),
);
}
getListPosition(BuildContext context) {
List<Widget> list = [];
for (int i = 0; i < plans.length; i++) {
list.add(AnimatedPositioned(
duration: Duration(seconds: 1),
top: getTopGap(i),
child: InkWell(
onTap: () {},
child: Container(
width: MediaQuery.of(context).size.width * 0.9,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.grey,
border: Border.all(
color: ColorsList.cardBorder,
)),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
alignment: Alignment.center,
padding: const EdgeInsets.all(10),
child: Text(
plans[i],
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: ScreenUtil().setSp(20),
),
),
decoration: BoxDecoration(
color:
Color((math.Random().nextDouble() * 0xFFFFFF).toInt())
.withOpacity(1.0),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10))),
),
Divider(
color: ColorsList.cardBorder,
height: 1,
),
Container(
padding: const EdgeInsets.all(50),
alignment: Alignment.center,
)
],
),
),
),
));
}
return list;
}
double getTopGap(int i) {
return i * 80;
}
}
OUTPUT :

Can't reduce size of an elevated button

I am trying to reproduce Apple memo recorder button. Right now, I am trying to reduce the size of Stop Button. First, I have tried without the SizedBox and then with. I am getting the same result.Even if embedded in a SizedBox, I can not achieve what I want.
Please, can somebody tells me what I am missing? Thank you.
Container _RecordButton(){
return Container(
height: 90,
width: 90,
decoration: BoxDecoration(
border: Border.all(
width: 4.0,
color: Colors.grey,
),
shape: BoxShape.circle,
),
child: Padding(
padding: EdgeInsets.all(4.0),
child: isRecording == false?
_createRecordElevatedButton() : _createStopElevatedButton()),);
}
ElevatedButton _createRecordElevatedButton(
{IconData icon, Function onPressFunc}) {
return ElevatedButton(
onPressed: () {
if (isRecording = false){
setState(() {
isRecording = true;
});
}},
style: ButtonStyle(
shape: MaterialStateProperty.all(CircleBorder()),
padding: MaterialStateProperty.all(EdgeInsets.all(20)),
backgroundColor: MaterialStateProperty.all(Colors.red), // <-- Button color
/*overlayColor: MaterialStateProperty.resolveWith<Color>((states) {
if (states.contains(MaterialState.pressed))
return Colors.red; // <-- Splash color
}*/));
}
SizedBox _createStopElevatedButton(
{IconData icon, Function onPressFunc}) {
return SizedBox(
height: 14,
width: 14,
child: ElevatedButton(
onPressed: () {
/* if (isRecording = true){
setState(() {
isRecording = false;
});
}*/
},
style: ButtonStyle(
fixedSize: MaterialStateProperty.all(Size(10,10)),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0),
side: BorderSide(color: Colors.red)
)
),
padding: MaterialStateProperty.all(EdgeInsets.all(20)),
backgroundColor: MaterialStateProperty.all(Colors.red), // <-- Button color
/*overlayColor: MaterialStateProperty.resolveWith<Color>((states) {
if (states.contains(MaterialState.pressed))
return Colors.red; // <-- Splash color
}*/)),
);
}
Wrap your elevated button with container and give height and width accordingly.
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(color: Colors.grey)),
child: Container(
padding: EdgeInsets.all(7),
width: 50.0,
height: 50.0,
child: ElevatedButton(
onPressed: () {},
style: ButtonStyle(
fixedSize: MaterialStateProperty.all(Size(10, 10)),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
side: BorderSide(color: Colors.red))),
padding: MaterialStateProperty.all(EdgeInsets.all(20)),
backgroundColor: MaterialStateProperty.all(Colors.red),
),
child: null,
)),
),
Please replace your code with below code:
class MyElevatedButton extends StatefulWidget {
const MyElevatedButton({Key? key}) : super(key: key);
#override
_MyElevatedButtonState createState() => _MyElevatedButtonState();
}
class _MyElevatedButtonState extends State<MyElevatedButton> {
bool isRecording=false;
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
height: 90,
width: 90,
decoration: BoxDecoration(
border: Border.all(
width: 4.0,
color: Colors.grey,
),
shape: BoxShape.circle,
),
child: Padding(
padding: EdgeInsets.all(4.0),
child: isRecording == false
? _createRecordElevatedButton(icon: Icons.add)
: _createStopElevatedButton(icon: Icons.minimize,onPressFunc: (){})),
),
],
),
),
),
);
}
/* Container _RecordButton() {
return Container(
height: 90,
width: 90,
decoration: BoxDecoration(
border: Border.all(
width: 4.0,
color: Colors.grey,
),
shape: BoxShape.circle,
),
child: Padding(
padding: EdgeInsets.all(4.0),
child: isRecording == false
? _createRecordElevatedButton()
: _createStopElevatedButton()),
);
}*/
Widget _createRecordElevatedButton(
// ignore: unused_element
{required IconData icon,/* VoidCallback onPressFunc*/}) {
return ElevatedButton(
onPressed: () {
if (isRecording = false) {
setState(() {
isRecording = true;
});
}
},
style: ButtonStyle(
shape: MaterialStateProperty.all(CircleBorder()),
padding: MaterialStateProperty.all(EdgeInsets.all(20)),
backgroundColor:
MaterialStateProperty.all(Colors.red), // <-- Button color
/*overlayColor: MaterialStateProperty.resolveWith<Color>((states) {
if (states.contains(MaterialState.pressed))
return Colors.red; // <-- Splash color
}*/
), child: Text('play'),);
}
// ignore: unused_element
SizedBox _createStopElevatedButton({required IconData icon, required VoidCallback onPressFunc}) {
return SizedBox(
height: 14,
width: 14,
child: ElevatedButton(
onPressed: () {
/* if (isRecording = true){
setState(() {
isRecording = false;
});
}*/
},
style: ButtonStyle(
fixedSize: MaterialStateProperty.all(Size(10, 10)),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0),
side: BorderSide(color: Colors.red))),
padding: MaterialStateProperty.all(EdgeInsets.all(20)),
backgroundColor:
MaterialStateProperty.all(Colors.red), // <-- Button color
/*overlayColor: MaterialStateProperty.resolveWith<Color>((states) {
if (states.contains(MaterialState.pressed))
return Colors.red; // <-- Splash color
}*/
), child: Text('onPressed'),),
);
}
}
Try this code :
MyElevatedButton
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
class MyElevatedButton extends StatefulWidget {
const MyElevatedButton({Key? key}) : super(key: key);
#override
_MyElevatedButtonState createState() => _MyElevatedButtonState();
}
class _MyElevatedButtonState extends State<MyElevatedButton> {
bool isRecording=false;
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
height: 90,
width: 90,
decoration: BoxDecoration(
border: Border.all(
width: 4.0,
color: Colors.grey,
),
shape: BoxShape.circle,
),
child: Padding(
padding: EdgeInsets.all(4.0),
child: isRecording == false
? _createRecordElevatedButton() /*_createRecordElevatedButton(icon: Icons.add,)*/
: _createStopElevatedButton()),
),
],
),
),
),
);
}
Widget _createRecordElevatedButton(){
return GestureDetector(
onTap: (){
setState(() {
isRecording = true;
});
print('clickOnPressedButton');
},
child: Container(
decoration: BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
),
child: Center(child: Text('Play',style: TextStyle(fontSize: 12,color: Colors.white),)),
),
);
}
Widget _createStopElevatedButton(){
return GestureDetector(
onTap: (){
setState(() {
isRecording = false;
});
print('clickOnPressedButton');
},
child: Container(
decoration: BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
),
child: Center(child: Text('Pause',style: TextStyle(fontSize: 12,color: Colors.white),)),
),
);
}
}

flutter: My last data is hiding behind the navigation bar

in redmi note 8 pro I got Bottom RenderFlex overflowed by 84 pixels. And My last data is hiding behind the navigation bar.
in redmi note 8 pro I got Bottom RenderFlex overflowed by 84 pixels. And My last data is hiding behind the navigation bar.
in redmi 4. It looks like it
This is my event section code
import 'package:cwc/constants/top_card.dart';
import 'package:cwc/ui/Event/components/activities.dart';
import 'package:cwc/ui/Event/components/event_page_changer.dart';
import 'package:cwc/ui/Event/components/event_tab_view.dart';
import 'package:cwc/ui/Home/components/search_components.dart';
import 'package:cwc/ui/Home/home_page.dart';
import 'package:cwc/ui/footer/bottom_nav_bar.dart';
import 'package:cwc/ui/footer/bottom_nav_bar_event.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
class Event extends StatefulWidget {
const Event({Key? key}) : super(key: key);
#override
_EventState createState() => _EventState();
}
class _EventState extends State<Event> {
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: true,
backgroundColor: Color(0xff80CAD7),
body: SafeArea(
child: Column(
children: [
TopCard(),
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topRight: Radius.circular(24.0),
topLeft: Radius.circular(24.0)),
),
child: EventTab())
// EventPageChanger(),
// Expanded(child: Activities()),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.pushReplacement(
context, MaterialPageRoute(builder: (context) => HomePage()));
},
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
child: Image.asset('assets/btnavico.png'),
elevation: 5.0,
highlightElevation: 10,
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: Container(
// height: MediaQuery.of(context).size.height * (10 / 100),
child: BottomNavBarEvent()),
);
}
}
and this is my event tab secion code
import 'package:cwc/ui/CwcTv/components/slides/slide_component.dart';
import 'package:cwc/ui/CwcTv/components/videos/video_component.dart';
import 'package:cwc/ui/CwcTv/cwc_tv.dart';
import 'package:cwc/ui/Event/components/activities.dart';
import 'package:cwc/ui/Event/components/category_page.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
class EventTab extends StatefulWidget {
#override
_EventTabState createState() => _EventTabState();
}
class _EventTabState extends State<EventTab>
with SingleTickerProviderStateMixin, WidgetsBindingObserver {
TabController? controller;
#override
void initState() {
// TODO: implement initState
super.initState();
controller = TabController(length: 4, vsync: this);
controller!.addListener(_handleTabSelection);
WidgetsBinding.instance!.addObserver(this);
}
#override
void dispose() {
// TODO: implement dispose
super.dispose();
WidgetsBinding.instance!.removeObserver(this);
controller?.dispose();
}
void _handleTabSelection() {
setState(() {});
}
#override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
_tabSection(context, controller!),
],
);
}
}
Widget _tabSection(BuildContext context, TabController controller) {
return DefaultTabController(
length: 4,
child: SafeArea(
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 0, 0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(14, 10, 14, 0),
child: TabBar(
controller: controller,
unselectedLabelColor: Colors.grey,
indicatorColor: Colors.white,
isScrollable: true,
tabs: [
Tab(
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(10)),
child: Container(
width: 66,
height: 32,
color: controller.index == 0
? Color(0xff158998)
: Color(0xffF1F2F6),
// decoration: const BoxDecoration(
// borderRadius: BorderRadius.all(Radius.circular(10)),
// ),
child: Center(
child: Text(
'All',
style: GoogleFonts.poppins(
color: controller.index == 0
? Color(0xffffffff)
: Color(0xff8F9698),
fontSize: 12,
),
),
),
),
),
),
Tab(
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(10)),
child: Container(
width: 85,
height: 32,
color: controller.index == 1
? Color(0xff158998)
: Color(0xffF1F2F6),
// decoration: const BoxDecoration(
// color: Color(0xffF1F2F6),
// borderRadius: BorderRadius.all(Radius.circular(10)),
// ),
child: Center(
child: Text(
'Category',
style: GoogleFonts.poppins(
color: controller.index == 1
? Color(0xffffffff)
: Color(0xff8F9698),
fontSize: 12,
),
),
),
),
),
),
Tab(
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(10)),
child: Container(
width: 85,
height: 32,
color: controller.index == 2
? Color(0xff158998)
: Color(0xffF1F2F6),
// decoration: const BoxDecoration(
// color: Color(0xffF1F2F6),
// borderRadius: BorderRadius.all(Radius.circular(10)),
// ),
child: Center(
child: Text(
'Upcoming',
style: GoogleFonts.poppins(
color: controller.index == 2
? Color(0xffffffff)
: Color(0xff8F9698),
fontSize: 12,
),
),
),
),
),
),
Tab(
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(10)),
child: Container(
width: 66,
height: 32,
color: controller.index == 3
? Color(0xff158998)
: Color(0xffF1F2F6),
// decoration: const BoxDecoration(
// color: Color(0xffF1F2F6),
// borderRadius: BorderRadius.all(Radius.circular(10)),
// ),
child: Center(
child: Text(
'Free',
style: GoogleFonts.poppins(
color: controller.index == 3
? Color(0xffffffff)
: Color(0xff8F9698),
fontSize: 12,
),
),
),
),
),
),
],
),
),
SizedBox(
height: MediaQuery.of(context).size.height * (50 / 100),
child: TabBarView(controller: controller,
children: const [
Activities(),
CategoryPage(),
Activities(),
Activities(),
],
),
),
],
),
),
),
);
}
wrap the column widget into singalchildscrollview widget
body: SafeArea(
singlechildscrollview(
child: Column(
children: [
TopCard(),
],
),
),
try the code down below
import 'package:cwc/constants/top_card.dart';
import 'package:cwc/ui/Event/components/activities.dart';
import 'package:cwc/ui/Event/components/event_page_changer.dart';
import 'package:cwc/ui/Event/components/event_tab_view.dart';
import 'package:cwc/ui/Home/components/search_components.dart';
import 'package:cwc/ui/Home/home_page.dart';
import 'package:cwc/ui/footer/bottom_nav_bar.dart';
import 'package:cwc/ui/footer/bottom_nav_bar_event.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
class Event extends StatefulWidget {
const Event({Key? key}) : super(key: key);
#override
_EventState createState() => _EventState();
}
class _EventState extends State<Event> {
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: true,
backgroundColor: Color(0xff80CAD7),
body: SafeArea(
child: body: SingleChildScrollView(
child:Column(
children:[
TopCard(),
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topRight: Radius.circular(24.0),
topLeft: Radius.circular(24.0)),
),
child: EventTab())
// EventPageChanger(),
// Expanded(child: Activities()),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.pushReplacement(
context, MaterialPageRoute(builder: (context) => HomePage()));
},
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
child: Image.asset('assets/btnavico.png'),
elevation: 5.0,
highlightElevation: 10,
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: Container(
// height: MediaQuery.of(context).size.height * (10 / 100),
child: BottomNavBarEvent()),
);
}
}
i just wrap the column with SingleChildScrollView
hope it will fix the problem

Menu draw keeps returning two app bars. How to return only one?

I currently have a drawer menu that folds out and can easily switch between pages. Everything seems to be working except when I go to the designated page it returns two app bars.
As you can see (look at image),
there are two app bars being displayed I want to remove the blue one completely and have the icon on the white app bar toggle the controller (Look at code provided)
How would I be able to this? I know it has something to do with return scaffold and the appbar but I have no clue how to remove this without breaking the app.
Thanks,
Stefan
Code:
import 'package:mykitchen/Main Controllers/My Recipes/My Recipes.dart';
import 'hidden_drawer_menu.dart';
import 'package:mykitchen/Main Controllers/Settings+Acount/Settings.dart';
import 'package:mykitchen/Main Controllers/GroceryList/GroceryList.dart';
import 'package:mykitchen/Main Controllers/Pantry/Pantry.dart';
import 'package:mykitchen/Main Controllers/Meal Plan/MealPlan.dart';
import 'package:mykitchen/Main Controllers/Recipets/Recipets.dart';
class ExampleCustomMenu extends StatelessWidget {
#override
Widget build(BuildContext context) {
return SimpleHiddenDrawer(
menu: Menu(),
screenSelectedBuilder: (position, controller) {
Widget screenCurrent;
switch (position) {
case 0:
screenCurrent = Settings();
break;
case 1:
screenCurrent = MyRecipes();
break;
case 2:
screenCurrent = GroceryList();
break;
case 3:
screenCurrent = Pantry();
break;
case 4:
screenCurrent = MealPlan();
break;
case 5:
screenCurrent = Recipets();
break;
}
return Scaffold(
appBar: AppBar(
title: Text("Look at this "),
leading: IconButton(
icon: Icon(Icons.menu),
onPressed: () {
controller.toggle();
}),
),
backgroundColor: Color(0xFFFF1744),
body: screenCurrent,
);
},
);
}
}
class Menu extends StatefulWidget {
#override
_MenuState createState() => _MenuState();
}
class _MenuState extends State<Menu> with TickerProviderStateMixin {
AnimationController _animationController;
bool initConfigState = false;
#override
void initState() {
_animationController =
AnimationController(vsync: this, duration: Duration(milliseconds: 100));
super.initState();
}
#override
Widget build(BuildContext context) {
confListenerState(context);
return Container(
width: double.maxFinite,
height: double.maxFinite,
color: Colors.red,
child: Stack(
children: <Widget>[
Container(
width: double.maxFinite,
height: double.maxFinite,
),
FadeTransition(
opacity: _animationController,
child: Padding(
padding: const EdgeInsets.all(50.0),
child: Align(
alignment: Alignment.centerLeft,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
width: 200.0,
height: 150,
child: RaisedButton(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10.0))),
onPressed: () {
SimpleHiddenDrawerProvider.of(context)
.setSelectedMenuPosition(0);
},
child: Text(
"Settings",
style: TextStyle(color: Colors.black),
),
),
),
SizedBox(
width: 200.0,
child: RaisedButton(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10.0))),
onPressed: () {
SimpleHiddenDrawerProvider.of(context)
.setSelectedMenuPosition(1);
},
child: Text(
"My Recipes",
style: TextStyle(color: Colors.black),
)),
),
SizedBox(
width: 200.0,
child: RaisedButton(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10.0))),
onPressed: () {
SimpleHiddenDrawerProvider.of(context)
.setSelectedMenuPosition(2);
},
child: Text(
"Grocery List",
style: TextStyle(color: Colors.black),
)),
),
SizedBox(
width: 200.0,
child: RaisedButton(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10.0))),
onPressed: () {
SimpleHiddenDrawerProvider.of(context)
.setSelectedMenuPosition(3);
},
child: Text(
"Pantry",
style: TextStyle(color: Colors.black),
)),
),
SizedBox(
width: 200.0,
child: RaisedButton(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10.0))),
onPressed: () {
SimpleHiddenDrawerProvider.of(context)
.setSelectedMenuPosition(4);
},
child: Text(
"Meal Plan",
style: TextStyle(color: Colors.black),
)),
),
SizedBox(
width: 200.0,
child: RaisedButton(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10.0))),
onPressed: () {
SimpleHiddenDrawerProvider.of(context)
.setSelectedMenuPosition(5);
},
child: Text(
"Recipets",
style: TextStyle(color: Colors.black),
)),
),
],
),
),
),
),
],
),
);
}
void confListenerState(BuildContext context) {
if (!initConfigState) {
initConfigState = true;
SimpleHiddenDrawerProvider.of(context)
.getMenuStateListener()
.listen((state) {
if (state == MenuState.open) {
_animationController.forward();
}
if (state == MenuState.closing) {
_animationController.reverse();
}
});
}
}
}```
You can use Scaffold without specifying an AppBar. Like this:
Scaffold(
// AppBar used to be here. Now it's not.
backgroundColor: Color(0xFFFF1744),
body: screenCurrent,
);
Learn more about Scaffold from here.

How to achieve transparent background in ChoiceChip?

I am creating a set of selections using ChoiceChip widget. I wanted to make the chips to have transparent background under certain condition like this image
I tried putting backgroundColor: Colors.transparent, but it'll turn white instead of transparent.
Here is my codes:
String _selectedSize = "";
var sizes = ['XS', 'S', 'M', 'L', 'XL'];
_customChip(size) => InkWell(
child: Container(
width: 40.0,
height: 40.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: Colors.white,
),
child: Stack(
children: <Widget>[
Center(child: Text(size, style: _chipTextStyle,)),
Center(
child: RotationTransition(
turns: AlwaysStoppedAnimation(315/360),
child: Container(height: 1.0, color: Colors.grey),
),
),
],
),
),
);
return Wrap(
alignment: WrapAlignment.center,
crossAxisAlignment: WrapCrossAlignment.center,
children: sizes.map((size) {
return ChoiceChip(
pressElevation: 1.0,
backgroundColor: Colors.transparent, // this doesn't work
label: _customChip(size),
labelPadding: EdgeInsets.symmetric(horizontal: 2.0),
padding: EdgeInsets.all(2.0),
materialTapTargetSize: MaterialTapTargetSize.padded,
shape: CircleBorder(),
selected: _selectedSize == size,
selectedColor: _themeColor,
onSelected: (isSelected) {
setState(() {
_selectedSize = size;
});
},
);
}).toList(),
);
Is there any idea how to make it transparent, or I should use widgets other than ChoiceChip? Thanks!
The Chip widget has a material which is colored according to the Theme. You can change that by changing the Theme.canvasColor, like this:
Theme(
data: ThemeData(canvasColor: Colors.transparent),
child: Chip(
label:Container(/*your widget*/),
backgroundColor: Colors.transparent, // or any other color
),
)
Or, you can keep your old Theme (except the canvasColor) by doing this:
Theme(
data: Theme.of(context).copyWith(canvasColor: Colors.transparent),
child: Chip(
label: Container(/*your widget*/),
backgroundColor: Colors.transparent, // or any other color
),
)
I have tried so many thigns with ChoiceChips for transparent background and not getting success then i decided to do it in another way as you also asked for alternate option, so i have created example for you where it similarly works same as ChoiceChips:
Note: For unselected background color i used
"Colors.grey.withOpacity(0.1)" but you can also use
"Colors.transparent"
import 'package:flutter/material.dart';
class MyChoiceChipsRadio extends StatefulWidget {
createState() {
return CustomRadioState();
}
}
class CustomRadioState extends State<MyChoiceChipsRadio> {
List<RadioModel> sampleData = List<RadioModel>();
#override
void initState() {
// TODO: implement initState
super.initState();
sampleData.add(RadioModel(false, 'XS'));
sampleData.add(RadioModel(false, 'S'));
sampleData.add(RadioModel(false, 'M'));
sampleData.add(RadioModel(false, 'L'));
sampleData.add(RadioModel(false, 'XL'));
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("ListItem"),
),
body: Stack(
children: <Widget>[
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/back_image.png"),
fit: BoxFit.cover,
),
)
),
ListView.builder(
itemCount: sampleData.length,
itemBuilder: (BuildContext context, int index) {
return InkWell(
//highlightColor: Colors.red,
splashColor: Colors.blueAccent,
onTap: () {
setState(() {
sampleData.forEach((element) => element.isSelected = false);
sampleData[index].isSelected = true;
});
},
child: RadioItem(sampleData[index]),
);
},
),
],
),
);
}
}
class RadioItem extends StatelessWidget {
final RadioModel _item;
RadioItem(this._item);
#override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.all(15.0),
child: Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Container(
height: 50.0,
width: 50.0,
child: Center(
child: Text(_item.buttonText,
style: TextStyle(
color:
_item.isSelected ? Colors.red : Colors.grey,
//fontWeight: FontWeight.bold,
fontSize: 18.0)),
),
decoration: BoxDecoration(
color: _item.isSelected
? Colors.white
: Colors.grey.withOpacity(0.1),
shape: BoxShape.circle,
border: Border.all(color: _item.isSelected
? Colors.red
: Colors.grey, width: 1.0)
),
),
],
),
);
}
}
class RadioModel {
bool isSelected;
final String buttonText;
RadioModel(this.isSelected, this.buttonText);
}
Hope it helps :)