im using sliding_up_panel package i want to add my location button above the panel so i build it like this, the problem is there is a shadow after i set my sliding_up_panel color to Colors.transparent and i cannot get rid of it, or if there is any good approach to build this common map things my location and sliding panel because i don't know any method to build it
this is my panel code
SlidingUpPanel(
controller: _panelC,
minHeight: MediaQuery.of(context).size.height * 0.15,
maxHeight: MediaQuery.of(context).size.height * 0.8,
panelSnapping: true,
snapPoint: 0.4,
color: Colors.transparent,
backdropOpacity: 0,
backdropColor: Colors.transparent,
backdropEnabled: false,
parallaxEnabled: true,
parallaxOffset: 0.5,
defaultPanelState: PanelState.CLOSED,
panelBuilder: (controller) {
return _buildPanel(controller);
},
body: _buildMap(),
),
this is my panel content
Widget _buildPanel(controller) {
return Column(
children: [
Align(
alignment: Alignment.centerRight,
child: ElevatedButton(
child: Icon(
Icons.my_location,
color: Colors.white,
),
onPressed: () {},
style: ElevatedButton.styleFrom(
fixedSize: const Size(48, 48),
shape: const CircleBorder(),
),
),
),
SizedBox(height: 16),
Expanded(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.vertical(
top: Radius.circular(16),
),
),
child: Column(
children: [
// list of place to go
Expanded(
child: ListView(
controller: controller,
children: List.generate(
3,
(index) => _buildListTile(),
),
),
),
],
),
),
),
],
);
}
Let's just create a custom BoxShadow that takes the BlurStyle as parameter.
class CustomBoxShadow extends BoxShadow {
final BlurStyle blurStyle;
const CustomBoxShadow({
Color color = const Color(0xFF000000),
Offset offset = Offset.zero,
double blurRadius = 0.0,
this.blurStyle = BlurStyle.normal,
}) : super(color: color, offset: offset, blurRadius: blurRadius);
#override
Paint toPaint() {
final Paint result = Paint()
..color = color
..maskFilter = MaskFilter.blur(this.blurStyle, blurSigma);
assert(() {
if (debugDisableShadows)
result.maskFilter = null;
return true;
}());
return result;
}
}
Now we can use it like this :
import 'package:flutter/material.dart';
import 'package:sliding_up_panel/sliding_up_panel.dart';
void main() {
runApp(
MaterialApp(
home: Scaffold(
body: SlidingUpPanel(
boxShadow: [
new CustomBoxShadow(
color: Colors.black,
offset: new Offset(10.0, 10.0),
blurRadius: 0.0,
blurStyle: BlurStyle.outer
)
],
panel: const Center(
child: Text('my slide content'),
),
body: const Center(
child: Text('my body'),
),
)
),
),
);
}
Play around with blurStye, blurRadius, offset to meet your need
Related
I'm having bottom overflowed by pixels flutter when showing keyboard, i tried SingleChildSCrollView and still couldn't find the solution for it. my aim to make the Get.defaultDialog scrollable.
here my code :
class AddCard extends StatelessWidget {
final homeCtrl = Get.find<HomeController>();
AddCard({super.key});
#override
Widget build(BuildContext context) {
final icons = getIcons();
var squareWidth = Get.width - 12.0.wp;
return Container(
width: squareWidth / 2,
height: squareWidth / 2,
margin: EdgeInsets.all(3.0.wp),
child: InkWell(
onTap: () async {
await Get.defaultDialog(
titlePadding: EdgeInsets.symmetric(vertical: 5.0.wp),
radius: 5,
title: 'Task Type',
content: Form(
key: homeCtrl.formKey,
child: Column(
children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: 3.0.wp),
child: TextFormField(
controller: homeCtrl.editCtrl,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'title',
),
validator: (value) {
if (value == null || value.trim().isEmpty) {
return 'Please enter your task title';
}
return null;
},
),
),
Padding(
padding: EdgeInsets.symmetric(vertical: 5.0.wp),
child: Wrap(
spacing: 2.0.wp,
children: icons
.map((e) => Obx(() {
final index = icons.indexOf(e);
return ChoiceChip(
selectedColor: Colors.grey[200],
pressElevation: 0,
backgroundColor: Colors.white,
label: e,
selected: homeCtrl.chipIndex.value == index,
onSelected: (bool selected) {
homeCtrl.chipIndex.value =
selected ? index : 0;
},
);
}))
.toList(),
),
),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: blue,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
minimumSize: const Size(150, 40),
),
onPressed: () {
if (homeCtrl.formKey.currentState!.validate()) {
int icon =
icons[homeCtrl.chipIndex.value].icon!.codePoint;
String color =
icons[homeCtrl.chipIndex.value].color!.toHex();
var task = Task(
title: homeCtrl.editCtrl.text,
icon: icon,
color: color,
);
}
},
child: const Text("Confirm"),
),
],
),
));
},
child: DottedBorder(
color: Colors.grey[400]!,
dashPattern: const [8, 4],
child: Center(
child: Icon(
Icons.add,
size: 10.0.wp,
color: Colors.grey,
),
)),
),
);
}
}
The widget that makes the error is the Get.defaultDialog().
There are two ways:
You can use the resizeToAvoidBottomInset property on the Scaffold widget.
You can use ListView instead Column:
onTap: () async {
await Get.defaultDialog(
radius: 5,
titlePadding: EdgeInsets.symmetric(vertical: 5.0),
title: Text('Task Type'),
content: SizedBox(
height: 500,//your height
width: 300, //your width
child:
Form(
child: ListView(
children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: 3.0),
child: TextFormField(
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'title',
),
),
),
Padding(
padding: EdgeInsets.symmetric(vertical: 5.0),
child: Wrap(
spacing: 2.0,
children: List.generate(//replace with your content
100,
(index) => Container(
height: 20,
width: 50,
padding: EdgeInsets.all(20),
color: Colors.red,
))),
),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
minimumSize: const Size(150, 40),
),
onPressed: () {},
child: const Text("Confirm"),
),
],
),
),
),
),
);
It`s important to give your dialog a fixed height and width, in this defined area it's possible to make a scrollable widget work.
If your aim is to make the dialog scrollable, Use ListView with defined height.
Further for your SizedBox to work as expected in case of any overplexes use the Flexible widget
Try the code structure:
GetDialog
|_Flexible
|_SizedBox 👈Define proper height and width here
|_ListView
I can't really understand your question well because you only posted part of the codes, but try wrapping your Scaffold body with SingleChildScrollView.
maybe you're using the SingleChildScrollView at a wrong place.
I want to create a progress bar in flutter which is like this
I get the data of week from backend but I have to create it this way.
and the icon on weeks or survey should be touchable.
thanks in advance.
Still a lot of things to change, but i thing it should be enough for the beginning
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Example',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
#override
Widget build(BuildContext context) {
List<String> points = [
'Survey',
'Week 1',
'Week 2',
'Week 3',
'Week 4',
];
var lineWidth =
MediaQuery.of(context).size.width - 16.0; // screen width - 2 * padding
var space = lineWidth / points.length; //space between dots
var currentSteps = 3; // <---- change this one
return Scaffold(
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Center(
child: SizedBox(
height: 60.0,
child: Stack(
children: [
//grey line
Positioned(
top: 15,
left: 0,
right: 0,
child: Container(
height: 2.0,
width: double.infinity,
color: Colors.grey,
),
),
//red line
Positioned(
top: 15,
left: 0,
child: Container(
height: 2.0,
width: space * (currentSteps - 1) + space / 2,
color: Colors.orange,
),
),
//circles
Row(
children: points
.asMap()
.map((i, point) => MapEntry(
i,
SizedBox(
width: space,
child: Column(
children: [
Stack(
children: [
Container(
height: 30.0,
width: 30.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
width: 1.5,
color: i == currentSteps - 1
? Colors.orange
: Colors.transparent,
),
),
child: Center(
child: Container(
height: 20.0,
width: 20.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: i < currentSteps
? Colors.orange
: Colors.grey,
),
),
),
),
if (i < currentSteps - 1)
const SizedBox(
height: 30.0,
width: 30.0,
child: Center(
child: Icon(
Icons.check,
size: 16.0,
color: Colors.white,
),
),
),
],
),
const SizedBox(height: 4.0),
Text(
point,
textAlign: TextAlign.left,
style: TextStyle(
color: i < currentSteps
? Colors.orange
: Colors.grey,
),
),
],
),
),
))
.values
.toList(),
),
],
),
),
),
),
);
}
}
You can try basic Stepper widget with type: StepperType.horizontal. As for the UI you like im_stepper package. If it fails to satisfy you can create custom widget with Stack and Row.
Try basic Stepper widget of flutter. if its not working properly then you need to create custom widget.
Using persistent_bottom_nav_bar: ^5.0.2, how do I detect that the user is scrolling on a list views of items on connection_view.dart page from bottom_nav_bar.dart page? So if it detects, I want the bottom_nav_bar to be hidden when user scrolls down.
bottom_nav_bar.dart, my bottom navigation bar
Widget build(BuildContext context) {
return Sizer(builder: ((context, orientation, deviceType) {
return Scaffold(
body: PersistentTabView(context,
screens: const [
ClientConnection(),
ClientDiscover(),
ClientDiscover(),
ClientDiscover()
],
items: _navBarsItems(),
navBarStyle: NavBarStyle.style1,
bottomScreenMargin: 0,
navBarHeight: 60,
padding: const NavBarPadding.all(5),
margin: const EdgeInsets.only(
bottom: 15,
left: 20,
right: 20,
),
decoration: NavBarDecoration(
borderRadius: BorderRadius.circular(30),
boxShadow: const [
BoxShadow(
color: Colors.grey,
blurRadius: 5,
offset: Offset(2, 2))
])),
List<PersistentBottomNavBarItem> _navBarsItems() {
return [
PersistentBottomNavBarItem(
icon: SvgPicture.asset(
'assets/active-connection-icon.svg',
width: 5.w,
),
title: ("CONNECTIONS"),
inactiveIcon: SvgPicture.asset(
'assets/inactive-connection-icon.svg',
width: 5.w,
),
),
PersistentBottomNavBarItem(
icon: SvgPicture.asset(
'assets/active-discover-icon.svg',
width: 5.w,
),
title: ("DISCOVER"),
inactiveIcon: SvgPicture.asset(
'assets/inactive-discover-icon.svg',
width: 5.w,
),
),
PersistentBottomNavBarItem(
icon: SvgPicture.asset(
'assets/active-profile-icon.svg',
width: 5.w,
),
title: ("PROFILE"),
inactiveIcon: SvgPicture.asset(
'assets/inactive-profile-icon.svg',
width: 5.w,
),
),
PersistentBottomNavBarItem(
icon: SvgPicture.asset(
'assets/active-notification-icon.svg',
width: 5.w,
),
title: ("NOTIFICATIONS"),
inactiveIcon: SvgPicture.asset(
'assets/inactive-notification-icon.svg',
width: 5.w,
),
),
connection_view.dart,my list view of items
Widget build(BuildContext context) {
return Sizer(builder: ((context, orientation, deviceType) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
elevation: 0,
toolbarHeight: 10.h,
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Connections',
style: TextStyle(color: Colors.black),
),
SizedBox(
width: 2.w,
),
Container(
width: 10.w,
height: 6.h,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Colors.blue,
),
),
],
),
),
body: ListView.builder(
controller: _scrollController,
physics: ClampingScrollPhysics(),
itemBuilder: (_, i) => ListTile(title: Text('Item $i')),
itemCount: 20,
),
);
}));
You need two things: listen to scrolling events and update the visibility of your app bar accordingly.
To do that you will need a StatefulWidget which contains the app bar as well, create two members in the state class to track scrolling direction and app bar visibility:
bool _showAppBar = true;
bool _isScrollingDown = false;
Wrap the app bar into a Visibility widget depending on the _showAppBar member:
...
Visibility(visible: _showAppBar, child: YourBottomNavBarWidgetHere()),
...
Register the listener to detect scrolling direction and update the visibility. I suggest using initState and dispose methods:
#override
void initState() {
super.initState();
_scrollController.addListener(_scrollListener);
}
#override
void dispose() {
_scrollController.removeListener(_scrollListener);
super.dispose();
}
scrollListener() {
if (_scrollController.position.userScrollDirection ==
ScrollDirection.reverse && !_isScrollingDown) {
_isScrollingDown = true;
setState(() {
_showAppBar = false;
});
}
else if (_scrollController.position.userScrollDirection ==
ScrollDirection.forward && _isScrollingDown) {
_isScrollingDown = false;
setState(() {
_showAppBar = true;
});
}
}
Alternatively, you can use an AnimatedContainer instead of Visibility. This way the app bar will be hidden and shown animated:
AnimatedContainer(
height: _showAppBar ? kToolbarHeight : 0.0,
duration: const Duration(milliseconds: 300),
child: YourBottomNavBarWidgetHere()),
What I have done till now is make widget draggable and a drag target according to my requirements. What i want is when the user drops the draggable container into the drag target i want to show that dragged widget inside that big drag target container and able to score if that is the right option or not.
second problem i am having is that i am using Text to speech for the sound and it is not working i tried many things but still it isn't working. i have a play button and give it a letter like A,B,D,G etc. whenever user presses the button i want to play the sound of that button and drag the right container into the drag target. Thankyou for your help.
// ignore_for_file: prefer_const_constructors, file_names, non_constant_identifier_names
import 'package:dyslexia/pages/round_2/Q8sound.dart';
import 'package:dyslexia/utilities/nextButton.dart';
import 'package:flutter/material.dart';
import 'package:flutter_tts/flutter_tts.dart';
import '../../utilities/QuestionWidget.dart';
class Q1DAD extends StatefulWidget {
const Q1DAD({Key? key}) : super(key: key);
#override
State<Q1DAD> createState() => _Q1DADState();
}
class _Q1DADState extends State<Q1DAD> {
String question =
"Listen to this letter sound and then choose the letter whose sound you hear";
var changeButton = false;
var score = 0;
final FlutterTts flutterTts = FlutterTts();
speak(word) async {
await flutterTts.setLanguage("en-US");
await flutterTts.setPitch(1);
await flutterTts.setVolume(10.0);
await flutterTts.speak(word);
}
var word = "M";
bool isPlayingMsg = false;
bool draged = false;
bool showDRag = false;
#override
Widget build(BuildContext context) {
bool isPlayingMsg = false;
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: true,
backgroundColor: Colors.cyan,
title: Text("AD&DY"),
),
body: Padding(
padding: const EdgeInsets.all(14.0),
child: Column(children: [
QuestionWidget(question: question),
SizedBox(height: MediaQuery.of(context).size.height * 0.05),
Material(
elevation: 5,
color: Colors.cyan[50],
child: ListTile(
onTap: () async {
speak(word);
isPlayingMsg = true;
},
leading: Icon(isPlayingMsg ? Icons.stop : Icons.play_arrow),
title: Text(isPlayingMsg ? "Stop" : "Play",
textScaleFactor: 1.2,
style: TextStyle(
color: Colors.black,
)),
),
),
Divider(
thickness: 1.0,
),
SizedBox(height: MediaQuery.of(context).size.height * 0.05),
Column(
children: [
DragTarget1(),
SizedBox(height: MediaQuery.of(context).size.height * 0.07),
Wrap(
spacing: 10,
runSpacing: 5,
children: [
draggableWord("M", false, score),
draggableWord("N", false, score),
draggableWord("O", false, score),
draggableWord("R", false, score),
],
),
],
),
SizedBox(height: MediaQuery.of(context).size.height * 0.1),
nextButton(changeButton: changeButton, Location: Q8sound()),
]),
),
);
}
int acceptedData = 0;
Widget DragTarget1() {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
DragTarget<int>(
builder: (
BuildContext context,
List<dynamic> accepted,
List<dynamic> rejected,
) {
return Material(
elevation: 10,
borderRadius: BorderRadius.circular(80),
child: Container(
height: 100.0,
width: 250.0,
color: Color.fromARGB(255, 78, 166, 178),
child: draged
? Container(
height: 50,
width: 70,
color: Colors.lightGreenAccent,
child: Align(
child: Text(word),
),
)
: Center(
child: Text('Drag target here'),
),
),
);
},
onAccept: (int data) {
setState(() {
draged = true;
showDRag = true;
});
},
),
],
);
}
Widget draggableWord(word, option, score) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
showDRag
? SizedBox()
: Draggable<int>(
// Data is the value this Draggable stores.
data: 10,
feedback: Container(
color: Colors.yellow[100],
height: 50,
width: 70,
child: Center(child: Text(word)),
),
childWhenDragging: Material(
elevation: 5,
borderRadius: BorderRadius.circular(10),
child: Container(
height: 50.0,
width: 70.0,
color: Colors.grey,
child: Center(
child: Text(""),
),
),
),
child: Material(
elevation: 5,
borderRadius: BorderRadius.circular(10),
child: Container(
height: 50,
width: 70,
color: Colors.lightGreenAccent,
child: Center(
child: Text(word),
),
),
),
)
],
);
}
}
here is my question widget
import 'package:flutter/material.dart';
class QuestionWidget extends StatelessWidget {
const QuestionWidget({
Key? key,
required this.question,
}) : super(key: key);
final String question;
#override
Widget build(BuildContext context) {
return Material(
elevation: 12,
color: Color.fromARGB(255, 125, 200, 210),
shadowColor: Colors.grey,
borderRadius: BorderRadius.circular(8),
child: Container(
height: 80,
width: 280,
alignment: Alignment.center,
child: Text(question,
textScaleFactor: 1.2,
style: TextStyle(
color: Colors.black,
))),
);
}
}
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 :)