how to show music bar in flutter audio player application - flutter

I am developing an audio player application using flutter, I m using on_audio_query package to fetch audio files from storage, and just_audio package for the audio player.
I want to know how to create something like the bar that is shown in this image
thanks in advance

I wrote one solution in a dartpad for you: https://dartpad.dev/?id=491a65532b2f92590c71a48be4836135
As in my example, you can use a stream to update the progress indicator around the play button. Look at my getSecondsFromCurrentMinute method. Replace this with the stream from your package.
Full code:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: Colors.black,
),
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: Colors.black,
body: Align(
alignment: Alignment.bottomCenter,
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
// Get the the seconds from current minute.
//
// TODO: Make this your actual progress indicator
Stream<int> getSecondsFromCurrentMinute() async* {
final now = DateTime.now();
final seconds = now.second;
yield seconds;
await Future.delayed(Duration(seconds: 1 - seconds));
yield* getSecondsFromCurrentMinute();
}
#override
Widget build(BuildContext context) {
return FractionallySizedBox(
heightFactor: .15,
widthFactor: 1,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Song cover
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.white, borderRadius: BorderRadius.circular(10)),
),
// Padding
SizedBox(width: 15),
// Title and artist
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Title
Text(
"AUD-20190208-WA0007",
style: Theme.of(context).textTheme.headline5,
),
// Artist
Text(
"Unknown artist",
style: Theme.of(context)
.textTheme
.bodyText2
?.copyWith(color: Colors.grey.withOpacity(.6)),
),
],
),
// Padding between first 2 columns and Icons
Expanded(child: SizedBox.expand()),
//
// Play button and progress indicator
//
StreamBuilder<int>(
stream: getSecondsFromCurrentMinute(),
builder: (context, AsyncSnapshot<int> snapshot) {
double percentageOfSecond = (snapshot.data ?? 0) / 60;
return Container(
width: 40,
height: 40,
child: Stack(
children: [
// the circle showing progress
Positioned(
top: 0,
left: 0,
child: Container(
width: 40,
height: 40,
child: CircularProgressIndicator(
value: percentageOfSecond,
valueColor: AlwaysStoppedAnimation<Color>(
Colors.red,
),
backgroundColor: Colors.red.withOpacity(0.15),
),
),
),
// the play arrow, inside the circle
Positioned(
top: 0,
left: 0,
child: Container(
width: 35,
height: 35,
child: IconButton(
icon: Icon(
Icons.play_arrow,
color: Colors.red,
),
onPressed: () {},
),
),
),
],
),
);
}),
SizedBox(width: 8),
Container(
width: 40,
height: 40,
child: GestureDetector(
onTap: () {},
child: Icon(
Icons.skip_next,
color: Colors.red,
),
),
),
//
SizedBox(width: 8),
Container(
width: 40,
height: 40,
child: GestureDetector(
onTap: () {},
child: Icon(
Icons.menu,
color: Colors.red,
size: 35,
),
),
),
// Extra padding at the end of the row
SizedBox(width: 30),
],
),
);
}
}

You can use Slider widget to make progress bar.
#override
Widget build(BuildContext context) {
return Slider(
value: position.inSeconds.toDouble(),
min: 0.0,
max: duration.inSeconds.toDouble() ,
onChanged: (value) async {
final position = Duration(seconds: value.toInt());
await player.seek(position);
},
),
And put the duration and position value in the initState()
Duration duration = Duration.zero;
Duration position = Duration.zero;
#override
void initState() {
player.currentPosition.listen((positionValue){
setState(() {
position = positionValue;
});
});
player.current.listen((event) {
setState(() {
duration = event.audio.duration;
});
});

Related

Scroll to specific widget Flutter web

I am creating a simple web portfolio to have hand-on practice in flutter. I was wondering how other website work when we click on home/about/contact button the web scroll to that specific widget.
I tried to do this but didn't get it how to implement this functionality
Code example will be helpful and will be appreciated as upvote.
you can give global key to the widget you want to scroll to
e.g
final dataKey = new GlobalKey();
assign it to the widget
Container(key:dataKey);
and then on the button onpressed write this code
onPressed: (){
Scrollable.ensureVisible(dataKey.currentContext);
}
you could use this package scroll_to_id
and here is an exemple made by github#yusukeinouehatchout
import 'package:flutter/material.dart';
import 'package:scroll_to_id/scroll_to_id.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
ScrollToId? scrollToId;
final ScrollController scrollController = ScrollController();
List<Color> _colorList = [
Colors.green,
Colors.red,
Colors.yellow,
Colors.blue
];
void _scrollListener() {
print(scrollToId!.idPosition());
}
#override
void initState() {
super.initState();
/// Create ScrollToId instance
scrollToId = ScrollToId(scrollController: scrollController);
scrollController.addListener(_scrollListener);
}
/// Generate 10 Container
/// Case [Axis.horizontal] set buildStackHorizontal() to body
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Scroll to id',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
title: const Text('Scroll to id'),
),
body: buildStackVertical(),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.navigate_next),
onPressed: () {
scrollToId!.animateToNext(
duration: Duration(milliseconds: 500), curve: Curves.ease);
},
),
),
);
}
/// [Axis.vertical]
/// https://raw.githubusercontent.com/wiki/yusukeinouehatchout/scroll_to_id/gif/scroll_to_id_vertical.gif
Widget buildStackVertical() {
return Stack(
alignment: Alignment.topRight,
children: [
InteractiveScrollViewer(
scrollToId: scrollToId,
children: List.generate(10, (index) {
return ScrollContent(
id: '$index',
child: Container(
alignment: Alignment.center,
width: double.infinity,
height: 200,
child: Text(
'$index',
style: TextStyle(color: Colors.white, fontSize: 50),
),
color: _colorList[index % _colorList.length],
),
);
}),
),
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.white, width: 3),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: List.generate(10, (index) {
return GestureDetector(
child: Container(
width: 100,
alignment: Alignment.center,
height: 50,
child: Text(
'$index',
style: TextStyle(color: Colors.white),
),
color: _colorList[index % _colorList.length],
),
onTap: () {
/// scroll with animation
scrollToId!.animateTo('$index',
duration: Duration(milliseconds: 500),
curve: Curves.ease);
/// scroll with jump
// scrollToId.jumpTo('$index');
},
);
}),
),
)
],
);
}
/// [Axis.horizontal]
/// https://raw.githubusercontent.com/wiki/yusukeinouehatchout/scroll_to_id/gif/scroll_to_id_horizontal.gif
Widget buildStackHorizontal() {
return Column(
children: [
Container(
width: double.infinity,
decoration: BoxDecoration(
border: Border.all(color: Colors.white, width: 3),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: List.generate(10, (index) {
return Expanded(
child: GestureDetector(
child: Container(
alignment: Alignment.center,
height: 80,
child: Text(
'$index',
style: TextStyle(color: Colors.white),
),
color: _colorList[index % _colorList.length],
),
onTap: () {
/// scroll with animation
scrollToId!.animateTo('$index',
duration: Duration(milliseconds: 500),
curve: Curves.ease);
/// scroll with jump
// scrollToId.jumpTo('$index');
},
),
);
}),
),
),
Expanded(
child: InteractiveScrollViewer(
scrollToId: scrollToId,
scrollDirection: Axis.horizontal,
children: List.generate(10, (index) {
return ScrollContent(
id: '$index',
child: Container(
alignment: Alignment.center,
width: 200,
child: Text(
'$index',
style: TextStyle(color: Colors.white, fontSize: 50),
),
color: _colorList[index % _colorList.length],
),
);
}),
),
),
],
);
}
}
I faced the same problem but I managed to solve it with this package it's helpful and easy scroll_to_index
define a listview controller
ListView( controller: controller, )
then you just need to wrap the elements in your screen with AutoScrollTag like
AutoScrollTag(
key: ValueKey(index),
controller: controller,
index: index,
child: YOUR_CHILD_HERE
)
finally scroll to our element like this
controller.scrollToIndex(index, preferPosition: AutoScrollPosition.begin)

how to display a dragged container inside another container when dragged into it in flutter

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,
))),
);
}
}

Flutter How to send and show captured image/ video to next page?

I've created a screen where I can use a button to open the camera and take video. And above that button, I made a container to display the video. But I want to show this container containing video to display on the next page. As I am new to flutter, I believe my code is messy. Can you help me with how to do this?
And how to show multiple videos on a screen after taking them through this camera in a loop like this image here?
Here is my code -
class video_record02 extends StatefulWidget {
final Function? onSelectVideo;
const video_record02({Key? key, this.onSelectVideo});
#override
_video_record02State createState() => _video_record02State();
}
class _video_record02State extends State<video_record02> {
String dropdownValue = 'Bedroom';
File? storedVideo;
Future<void> _takeVideo() async {
final picker = ImagePicker();
final videoFile = await picker.pickVideo(
source: ImageSource.camera,
preferredCameraDevice: CameraDevice.rear,
maxDuration: Duration(
seconds: 25,
),
);
if (videoFile == null) {
return;
}
final rlyvideoFile = File(videoFile.path);
setState(() {
storedVideo = rlyvideoFile;
});
final appDir = await syspaths.getApplicationDocumentsDirectory();
final fileName = path.basename(rlyvideoFile.path);
final savedVideo = await rlyvideoFile.copy('${appDir.path}/$fileName');
widget.onSelectVideo?.call(savedVideo);
}
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.white,
body: Center(
child: ListView(
shrinkWrap: true,
children: [
Column(
children: [
Container(
width: 150,
height: 100,
decoration: BoxDecoration(
border: Border.all(
width: 0.5,
color: Colors.grey,
),
),
child: storedVideo != null
? VideoWidget(storedVideo!)
: Text(
'No Video Taken',
textAlign: TextAlign.center,
),
alignment: Alignment.center),
Align(
alignment: Alignment.center,
child: Column(
children: [
IconButton(
icon: Icon(Icons.play_circle_fill),
color: Colors.red,
iconSize: 100.0,
onPressed: _takeVideo,
),
],
),
),
Text(
'Click to start',
style: TextStyle(
fontSize: 25.0,
color: Colors.red,
fontWeight: FontWeight.w300,
),
),
Container(
margin: EdgeInsets.fromLTRB(125, 0, 125, 0),
height: 50,
padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
child: TextButton(
child: Text(
'< Back',
style: TextStyle(fontSize: 17, color: Colors.black),
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => video_record01()),
);
},
),
),
],
),
],
),
),
),
);
}
}

Flutter: i want to save the image from camera or gallery to next page after cropping it here is my code

I want to save the image to the next page but after cropping the image it opens the next page but the image is not saved, here is my code it opens the camera take the pic or open gallery but after cropping it only take to the next page what should I do to save the cropped image to next page.I tried a method but it returns the image on UIpage.
import 'package:flutter/material.dart';
import 'package:fyp/ui.dart';
import 'package:fyp/Analyze.dart';
void main() {
runApp(MaterialApp(home: MyApp()));
}
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Ui(),
),
);
}
}
import 'package:flutter/material.dart';
import 'package:fyp/Analyze.dart';
import 'dart:io';
import 'package:image_picker/image_picker.dart';
import 'package:image_cropper/image_cropper.dart';
class Ui extends StatefulWidget {
#override
_UiState createState() => _UiState();
}
class _UiState extends State<Ui> {
String path;
File _selectedFile;
bool _inProcess1 = false;
#override
void initState() {
super.initState();
}
getImage(ImageSource source) async {
this.setState((){
_inProcess1 = true;
});
File image = await ImagePicker.pickImage(source: source);
if(image != null){
File cropped = await ImageCropper.cropImage(
sourcePath: image.path,
aspectRatio: CropAspectRatio(
ratioX: 1, ratioY: 1),
compressQuality: 100,
maxWidth: 700,
maxHeight: 700,
compressFormat: ImageCompressFormat.jpg,
androidUiSettings: AndroidUiSettings(
toolbarColor: Colors.deepOrange,
toolbarTitle: "RPS Cropper",
statusBarColor: Colors.deepOrange.shade900,
backgroundColor: Colors.white,
)
);
this.setState((){
_selectedFile = cropped;
return Analyze();
_inProcess1 = false;
});
} else {
this.setState((){
_inProcess1 = false;
});
}
}
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(
elevation: 0,
toolbarHeight: 100,
leading:Padding(
padding: const EdgeInsets.fromLTRB(15, 20, 0, 0),
child: Column(
children: [
IconButton(icon: Icon(Icons.info_outlined, color: Colors.white,
size: 30,),
onPressed: ()=>null,),
Text(" Help",style: TextStyle(
color: Colors.white,
fontSize: 16,
), ),
],
),
),
actions: [
Padding(
padding: const EdgeInsets.fromLTRB(0, 20, 20, 0),
child: Column(
children: [
IconButton(icon: Icon(Icons.upload_outlined, color: Colors.white,
size: 30,),
onPressed: ()
{ getImage(ImageSource.gallery); }
),
Text("Upload",style: TextStyle(
color: Colors.white,
fontSize: 16,
), ),
],
),
)
],
),
backgroundColor: Colors.blue,
body: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(0, 90, 0, 60),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Stack(
alignment: Alignment.center,
children: [
Opacity(
opacity:0.6,
child: CircleAvatar( // use to create circle
backgroundColor: Colors.white,
radius: 80,
),
),
Opacity(
opacity:0.5,
child: CircleAvatar(
backgroundColor: Colors.white,
radius: 120,
),
),
Opacity(
opacity:0.3,
child: CircleAvatar(
backgroundColor: Colors.white,
radius: 150,
),
),
Opacity(
opacity:0.7,
child: CircleAvatar(
backgroundColor: Colors.blue,
radius: 180,
),
),
IconButton(
iconSize: 80,
icon: Icon(Icons.camera_alt, color: Colors.white,),
onPressed: () {
getImage(ImageSource.camera);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Analyze(
),
),
);
},
),
],
),
],
),
),
Text("Tap to scan", style: TextStyle(
color: Colors.white,
fontSize: 20,
),),
SizedBox(
height: 20,
width: 150,
child: Divider(
color: Colors.white,
thickness: 3,
),
),
],
),
),
);
}
}
import 'package:flutter/material.dart';
import 'dart:io';
class Analyze extends StatefulWidget {
#override
_AnalyzeState createState() => _AnalyzeState();
}
class _AnalyzeState extends State<Analyze> {
File _selectedFile;
bool _inProcess = false;
#override
Widget build(BuildContext context) {
Widget getImageWidget(File selectedFile) {
if (_selectedFile != null) {
return Image.file(
_selectedFile,
width: 250,
height: 250,
fit: BoxFit.cover,
);
} else {
return Image.asset(
"assets/placeholder.jpg",
width: 250,
height: 250,
fit: BoxFit.cover,
);
}
}
(_inProcess)
? Container(
color: Colors.white,
height: MediaQuery.of(context).size.height * 0.95,
child: Center(
child: CircularProgressIndicator(),
),
)
: Center();
return SafeArea(
child: Scaffold(
body: Column(
children: [
getImageWidget(_selectedFile),
],
),
),
);
}

Flutter - How to make a Material Button stationery while scrolling page

ADDED PICTURE:
Edited: June23, 2020
for clarification... I. need these two buttons to not move at all and stay at the same position, when I scroll these buttons are stationary but as the page scrolls the movement of the page moves the buttons so meaning it won't be on line 1 any more if I scroll to line 4 first button is on line 4 and second button is on line 5. I don't want them to move at all... I
Basically, since I need to make the image do a command I need to add a button and code in order for it to do it or its just a png image.
need to add many buttons over the text within the picture ...How can I achieve this ..? I tried different tactics but as the scroll moves the buttons move too ..
I am creating an APP which has a lot of emphasis on the image in the background as such, their is text in arabic on that image per line and I want to add "material buttons" on top of this text. I was able to do this ... but then I used single child scroll which I only want the image to scroll but not the buttons. I want the buttons to stay in one specific position and not scroll , since the logic is on swiping right -- user will see the invisible material button become active and show English text for that specific position on swiping left user will see the arabic text that is on the image ....
please help
EDITED THE CODE TO ONLY SHOW THE ISSUE AND GOT RID OF COMMENTED CODE to show just one stack. -
LAYOUT USED:
Stack and laid out Image with single scroll and closed it off
and after that added the Raised button,
Layout needed:
Just want the single child scroll to scroll the image not the raised buttons that are on top of the image. I want those buttons to be stationary .... Maybe its a positional problem, I need to add the a different type of scroll ?
import 'dart:io';
import 'package:Quran_highlighter/main.dart';
import 'package:flutter/rendering.dart';
import 'package:system_shortcuts/system_shortcuts.dart';
import 'package:Quran_highlighter/Widgets/NavDrawer.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:zoom_widget/zoom_widget.dart';
import 'package:flutter/gestures.dart';
class Aliflaammeem extends StatefulWidget {
#override
_AliflaammeemState createState() => _AliflaammeemState();
}
class _AliflaammeemState extends State<Aliflaammeem> {
changeTextEnglish() {
setState(() {
bool _visible = true;
_visible = _visible;
textHolder = "All Praise and Thanks is to Allah the lord of the worlds";
});
}
changeTextArabic() {
bool _visible = true;
setState(() {
_visible = _visible;
});
}
#override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations(
[DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]);
return Scaffold(
body: Stack(
children: <Widget>[
Center(child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: SafeArea(
top: true,
bottom: true,
right: true,
left: true,
child: Image(
image: AssetImage('test/assets/quranpg0.png'),
fit: BoxFit.cover
// ),
// ),
// ),
// ),
// ),
// Container(
// child:Align(
// alignment: Alignment(.00,-.7
// ),
// // color: Colors.red,
// child: FloatingActionButton(
// // color: Colors.red,
// elevation: 9,
// onPressed: () => 0,
// child: Text("Static "))
// ),
// ),
Container(
child: Align(
alignment: Alignment(.00, -.8
),
child: _visible
? MaterialButton(
height: 70.0,
// minWidth: 36.5,
// minWidth: 85.0,
minWidth: 100.0,
onPressed: () => changeTextArabic1(),
onLongPress: () => changeTextEnglish1(),
// child: Text(labels[i]),
child: Text(surah0),
// color: Colors.cyan[400],
color: Colors.purple[300],
highlightColor: Colors.blue,
shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(60.0)
),
textColor: Colors.white,
padding: EdgeInsets.only(left: 80, top: 2, right: 78, bottom: 5),
)
:Container(),
),
),
Container(
child: Align(
alignment: Alignment(.00, -.35
),
child: _visible
? MaterialButton(
height: 70.0,
// minWidth: 36.5,
// minWidth: 85.0,
minWidth: 100.0,
onPressed: () => changeTextArabic1(),
onLongPress: () => changeTextEnglish1(),
// child: Text(labels[i]),
child: Text(label0),
color: Colors.cyan[400],
// color: Colors.purple[300],
highlightColor: Colors.blue,
// shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(60.0)
// ),
textColor: Colors.white,
padding: EdgeInsets.only(left: -4, top: 2, right: -4, bottom: 5),
)
:Container(),
),
),
Container(
child: Align(
alignment: Alignment(.00, 0.1
),
child: _visible
? MaterialButton(
height: 70.0,
// minWidth: 36.5,
// minWidth: 85.0,
minWidth: 100.0,
onPressed: () => changeTextArabic1(),
onLongPress: () => changeTextEnglish1(),
// child: Text(labels[i]),
child: Text(label1),
color: Colors.cyan[400],
// color: Colors.purple[300],
highlightColor: Colors.blue,
// shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(60.0)
// ),
textColor: Colors.white,
padding: EdgeInsets.only(left: 20, top: 2, right: 33, bottom: 5),
)
:Container(),
),
),
// for(int i = 0; i< labels.length; i++)
Container(
child: Align(
alignment: Alignment(.00, 0.54
),
child: _visible
?
MaterialButton(
height: 70.0,
minWidth: 100,
onPressed: () => changeTextArabic1(),
onLongPress: () => changeTextEnglish1(),
// Positioned(
// top: 21,
child: Text(label2),
disabledTextColor: Colors.transparent,
color: Colors.cyan[300],
// color: Colors.purple[300],
highlightColor: Colors.blue,
// shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(60.0)
// ),
textColor: Colors.white,
padding: EdgeInsets.only(left: 90, top: 0, right: 100, bottom: 5),
)
:Container()
),
),
Container(
child: Align(
alignment: Alignment(.00, .99
),
child: _visible
?
MaterialButton(
height: 70.0,
minWidth: 100,
onPressed: () => changeTextArabic1(),
onLongPress: () => changeTextEnglish1(),
// Positioned(
// top: 21,
child: Text(label3),
disabledTextColor: Colors.transparent,
color: Colors.cyan[300],
// color: Colors.purple[300],
highlightColor: Colors.blue,
// shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(60.0)
// ),
textColor: Colors.white,
padding: EdgeInsets.only(left: 120, top: 2, right: 118, bottom: 5),
)
:Container()
),
),
GestureDetector(onPanUpdate: (DragUpdateDetails details) {
if (details.delta.dx > 0) {
print("right swipe english");
changeTextEnglish1();
setState(() {
});
} else if (details.delta.dx < 0) {
print("left swipe arabic");
changeTextArabic1();
setState(() {
});
}
}
)))))]));}}
UPDATE:
After some research I've concluded that you can use floatingActionButton and floatingActionButtonLocation to position a floatingActionButton that will not be affected by scrolling. You could also use Center of Align to position it where you want.
I hope this works for you!
Original post:
I think the easiest and most efficient way would be to use a raisedButton passed in buttomNavigationBar. I've seen people using a CustomScrollView but the button kind of stutters when doing that. buttonNavigationBar seems to be the best way to go. You can use color and elevation to blend in with your background.
Don't forget to flag this as an answer if it was any help!
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
final text = "echo\n" * 1000;
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("Static button"),
),
body: SingleChildScrollView(child: Text(text)),
bottomNavigationBar: Container(
color: Colors.white,
child: RaisedButton(
color: Colors.white,
elevation: 0,
onPressed: () => 0,
child: Text("Static Button"))),
),
);
}
}
I think you had to many Stack.
I just removed a few and made this working example.
Hope it's what you wanted.
class Aliflaammeem extends StatefulWidget {
#override
_AliflaammeemState createState() => _AliflaammeemState();
}
class _AliflaammeemState extends State<Aliflaammeem> {
var nameList = new List<String>();
final items = List<String>.generate(20, (i) => "Item ${i + 1}");
List<MaterialButton> buttonsList = new List<MaterialButton>();
#override
void initState() {
super.initState();
nameList.add("I love");
nameList.add("my ALLAH");
nameList.add("SWT Very Much");
}
List<String> labels = ['apple', 'banana', 'pineapple', 'kiwi'];
bool _visible = true;
int _counter = 0;
double _initial = 0.0;
var textHolder = "";
changeTextEnglish() {
setState(() {
_visible = true;
textHolder = "All Praise and Thanks is to Allah the lord of the worlds";
});
}
changeTextArabic() {
setState(() {
_visible = false;
});
}
#override
Widget build(BuildContext context) {
final title = 'Dismissing Items';
return Scaffold(
body: Center(
child: Stack(fit: StackFit.expand, children: <Widget>[
SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
children: <Widget>[
Container(
color: Colors.red,
height: 300,
),
Container(
color: Colors.blue,
height: 300,
),
Container(
color: Colors.green,
height: 300,
),
Container(
color: Colors.yellow,
height: 300,
),
],
),
),
Container(
child: Align(
alignment: Alignment(.27, 0.1),
child: _visible
? MaterialButton(
height: 70.0,
minWidth: 85.0,
onPressed: () => changeTextArabic(),
onLongPress: () => changeTextEnglish(),
child: Text('$textHolder'),
color: Colors.cyan[400],
highlightColor: Colors.blue,
textColor: Colors.white,
padding: EdgeInsets.only(left: 10, top: 2, right: -1, bottom: 5),
)
: Container(),
),
),
for (int i = 0; i < labels.length; i++)
Container(
child: Align(
alignment: Alignment(-.5, 0.1),
child: MaterialButton(
height: 70.0,
minWidth: 36.5,
onPressed: () => changeTextArabic(),
onLongPress: () => changeTextEnglish(),
child: Text(labels[i]),
disabledTextColor: Colors.transparent,
color: Colors.cyan[300],
highlightColor: Colors.blue,
textColor: Colors.white,
padding: EdgeInsets.only(left: 46, top: 2, right: -20, bottom: 5),
),
// ),
),
),
GestureDetector(onPanUpdate: (DragUpdateDetails details) {
if (details.delta.dx > 0) {
print("right swipe english");
changeTextEnglish();
setState(() {});
} else if (details.delta.dx < 0) {
print("left swipe arabic");
changeTextArabic();
setState(() {});
}
})
])));
}
}