I tried to create a slideshow as you can see and it works, but after I added the code to create Cards under my SlideShow, I got this error:
I/flutter (12937): Another exception was thrown: 'package:flutter/src/rendering/object.dart': Failed assertion: line 1645 pos 12: '!_debugDoingThisLayout': is not true.
I/flutter (12937): Another exception was thrown: RenderBox was not laid out: RenderFlex#57317 relayoutBoundary=up1 NEEDS-PAINT
I/flutter (12937): Another exception was thrown: NoSuchMethodError: The method '>' was called on null.
Please Help me to resolve this issue.
import 'package:flutter/material.dart';
import 'package:carousel_pro/carousel_pro.dart';
import 'package:flutter/services.dart';
void main() => runApp(new MyApp());
Widget myGridItems (String gridName, String gridImage, int color1, int color2){
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(24.0),
gradient: new LinearGradient(
colors: [
Color(color1),
Color(color2),
],
begin: Alignment.centerLeft,
end: new Alignment(1.0, 1.0),
)
),
child: Stack(
children: <Widget>[
Opacity(
opacity: 0.3,
child: Container(
decoration: new BoxDecoration(
borderRadius: BorderRadius.circular(24.0),
image: DecorationImage(
image: AssetImage('assets/s1.jpg'),
fit: BoxFit.fill)
),
),
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(child: Text("Job", style: TextStyle(color: Colors.white, fontSize: 16),)),
SizedBox(width: 10.0),
Container(child: Icon(Icons.school, color: Colors.white)),
SizedBox(width: 10.0),
Container(child: Text("Guide", style: TextStyle(color: Colors.white, fontSize: 16),)),
],
),
),
SizedBox(height: 10.0),
Padding(
padding: const EdgeInsets.only(left: 16.0),
child: Text(gridName, style: TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold),),
),
],
)
],
),
);
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown
]);
return new MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Carousel',
home: ImageCarousel(),
);
}
}
class ImageCarousel extends StatefulWidget {
_ImageCarouselState createState() => new _ImageCarouselState();
}
class _ImageCarouselState extends State<ImageCarousel> with SingleTickerProviderStateMixin {
Animation<double> animation;
AnimationController controller;
initState() {
super.initState();
controller = new AnimationController(
duration: const Duration(milliseconds: 2000), vsync: this);
animation = new Tween(begin: 0.0, end: 18.0).animate(controller)
..addListener(() {
setState(() {
// the state that has changed here is the animation object’s value
});
});
controller.forward();
}
#override
Widget build(BuildContext context) {
double screenHeight = MediaQuery.of(context).size.height;
Widget carousel = new Carousel(
boxFit: BoxFit.cover,
images: [
new AssetImage('assets/s1.jpg'),
new AssetImage('assets/s2.jpg'),
],
animationCurve: Curves.fastOutSlowIn,
animationDuration: Duration(seconds: 1),
);
Widget banner = new Padding(
padding: const EdgeInsets.only(top: 20.0, left: 20.0),
child: new Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(15.0),
bottomRight: Radius.circular(15.0)),
color: Colors.amber.withOpacity(0.5),
),
padding: const EdgeInsets.all(10.0),
child: new Text(
'Enter to learn, leave to achieve',
style: TextStyle(
fontFamily: 'fira',
fontSize: animation.value, //18.0,
//color: Colors.white,
),
),
),
// ),
// ),
);
return new Scaffold(
appBar: AppBar(
title: Text('Kelden Bilingual Higher Institute of Professional Studies\n'
'Accord N° 18-1020/L/MINSUP/SG/DDES/SD-ESUP/SDA/LMN du 03/12/2018\n'
'Arrêté N° 078/MINEFOP/SG/DFOP/SDGSF/SACD du 13/03/2017', textAlign: TextAlign.center, style: TextStyle(fontSize: 9.5,),),
),
backgroundColor: Colors.blue[200],
body: new Column(
children: <Widget>[
new Container(
padding: const EdgeInsets.fromLTRB(0, 1, 0, 90.0),
height: screenHeight / 2,
child: new ClipRRect(
borderRadius: BorderRadius.circular(0.0),
child: new Stack(
children: [
carousel,
banner,
],
),
),
),
GridView.count(
crossAxisCount: 2,
padding: EdgeInsets.all(16.0),
childAspectRatio: 0.9,
crossAxisSpacing: 10.0,
mainAxisSpacing: 10.0,
children: <Widget>[
myGridItems(gridName, gridImage, color1, color2)
],
)
],
),
);
}
dispose() {
controller.dispose();
super.dispose();
}
}
You just need to wrap your GridView with a Flexible so that it plays nice with the Column:
Flexible(
child: GridView.count(
primary: false,
crossAxisCount: 2,
padding: EdgeInsets.all(16.0),
childAspectRatio: 0.9,
crossAxisSpacing: 10.0,
mainAxisSpacing: 10.0,
children: <Widget>[
myGridItems(gridName, gridImage, Colors.blue, Colors.yellow)
],
),
)
Change the top of your myGridItems to this:
Widget myGridItems (String gridName, String gridImage, Color color1, Color color2){
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(24.0),
gradient: new LinearGradient(
colors: [
color1,
color2,
],
begin: Alignment.centerLeft,
end: new Alignment(1.0, 1.0),
)
Please note that I've changed the myGridItems call to:
myGridItems(gridName, gridImage, Colors.blue, Colors.yellow)
Related
I have a Scaffold that takes API Data and displays it. I also have a page controller with five different pages. The page controller passes a variable to my .where to tell him to sort after that specific thing for the correct page. For this to work the page needs to refreshed to display the new thing. That does not work since my getApiData is a future. I dont know how to solve this without rewriting most of my code.
import 'dart:convert';
import 'package:css_app/pages/JsonToDart.dart';
import 'package:flutter/material.dart';
//import '../models/deinModel_model.dart';
import 'package:http/http.dart' as http;
class StundenplanZeiger extends StatefulWidget {
StundenplanZeiger(
{Key? key, required this.headline, required this.tagController})
: super(key: key);
String headline;
String tagController;
#override
State<StundenplanZeiger> createState() =>
StundenplanZeigerState(headline: headline, tagController: tagController);
}
class StundenplanZeigerState extends State<StundenplanZeiger> {
List<Unterrichtsplan>? klassennameListe;
List<Unterrichtsplan>? klassennameListeSortiert;
StundenplanZeigerState({required this.headline, required this.tagController});
String headline;
String tagController;
Future<void> getApiData() async {
String url = 'MyAPI';
var response = await http.get(Uri.parse(url));
klassennameListe = jsonDecode(response.body)
.map((item) => Unterrichtsplan.fromJson(item))
.toList()
.cast<Unterrichtsplan>();
if (this.mounted) {
setState(() {});
}
klassennameListeSortiert = klassennameListe!
.where(
(item) => (item.klasse == "5a" && item.tag == tagController),
)
.toList();
}
#override
void initState() {
super.initState();
getApiData();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Stundenplan'),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.all(1.00),
alignment: Alignment.center,
child: Text(headline, style: TextStyle(fontSize: 20)),
),
if (klassennameListeSortiert != null)
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: ListView.builder(
itemCount: klassennameListeSortiert?.length,
itemBuilder: (BuildContext context, int index) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
alignment: Alignment.center,
padding: EdgeInsets.all(8.00),
margin: EdgeInsets.all(10),
constraints: BoxConstraints
.tightForFinite(), //Das hier könnte Fehler verursachen, sollte später die letzte Box bis unendlich lang sein, ist das hier wahrscheinlich schuld.
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
width: 2.0,
style: BorderStyle.solid,
),
borderRadius:
BorderRadius.all(Radius.circular(20.00)),
boxShadow: [
BoxShadow(
color: Colors.grey,
blurRadius: 4.0,
spreadRadius: 1.0,
),
],
color: Colors.white,
/*gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Colors.pink.shade100,
Colors.pink.shade50,
]),*/
),
child: Stack(
children: <Widget>[
Container(
child: Transform.translate(
offset: Offset(-10, -15),
child: Container(
alignment: Alignment.topLeft,
child: Container(
padding: EdgeInsets.all(6.00),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.grey[200],
boxShadow: [
BoxShadow(
color: Colors.black,
blurRadius: 4.0,
spreadRadius: 1.0,
),
]),
child: Text(
klassennameListe![index]
.stunde
.toString(),
),
),
),
),
),
Positioned(
child: Container(
alignment: Alignment.center,
child: Text(
klassennameListe![index].fach.toString(),
style: TextStyle(
fontSize: 70,
),
),
),
),
Positioned(
top: 0,
right: 0,
child: Container(
padding: EdgeInsets.all(6.00),
margin: EdgeInsets.all(6.00),
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
width: 1.5,
style: BorderStyle.solid,
),
borderRadius: BorderRadius.all(
Radius.circular(20.00)),
boxShadow: [
BoxShadow(
color: Colors.grey,
blurRadius: 4.0,
spreadRadius: 1.0,
),
],
color: Colors.white,
/*gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Colors.pink.shade100,
Colors.pink.shade50,
]),*/
),
child: Text(
klassennameListe![index].raum.toString(),
),
),
),
Positioned(
bottom: 0,
right: 0,
child: Container(
padding: EdgeInsets.all(6.00),
margin: EdgeInsets.all(6.00),
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
width: 1.5,
style: BorderStyle.solid,
),
borderRadius: BorderRadius.all(
Radius.circular(20.00)),
boxShadow: [
BoxShadow(
color: Colors.grey,
blurRadius: 4.0,
spreadRadius: 1.0,
),
],
color: Colors.white,
/*gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Colors.pink.shade100,
Colors.pink.shade50,
]),*/
),
child: Text(
klassennameListe![index]
.lehrer
.toString(),
),
),
),
Positioned(
bottom: 0,
left: 0,
child: Container(
padding: EdgeInsets.all(6.00),
margin: EdgeInsets.all(6.00),
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
width: 1.5,
style: BorderStyle.solid,
),
borderRadius: BorderRadius.all(
Radius.circular(20.00)),
boxShadow: [
BoxShadow(
color: Colors.grey,
blurRadius: 4.0,
spreadRadius: 1.0,
),
],
color: Colors.white,
/*gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Colors.pink.shade100,
Colors.pink.shade50,
]),*/
),
child: Text(
klassennameListe![index]
.klasse
.toString(),
),
),
),
],
),
),
],
);
}),
),
),
],
),
);
}
}
Here is the second code
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'StundenplanZeiger.dart';
late String stunde;
late int aktuellerTag = 1; //Muss noch abgeändert werden
class Stundenplan3 extends StatefulWidget {
const Stundenplan3({Key? key}) : super(key: key);
#override
_Stundenplan3State createState() => _Stundenplan3State();
}
class _Stundenplan3State extends State<Stundenplan3> {
final controller = PageController(initialPage: 1);
#override
void dispose() {
controller.dispose();
super.dispose();
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: PageView(
onPageChanged: (value) => StundenplanZeigerState.getApiData(),
controller: controller,
children: [
StundenplanZeiger(headline: "Montag", tagController: "1"),
StundenplanZeiger(headline: "Dienstag", tagController: "2"),
StundenplanZeiger(headline: "Mittwoch", tagController: "3"),
StundenplanZeiger(headline: "Donnerstag", tagController: "4"),
StundenplanZeiger(headline: "Freitag", tagController: "5"),
],
),
);
}
}
class StundenplanBody extends StatefulWidget {
StundenplanBody(
{Key? key, required this.headline, required this.tagController})
: super(key: key);
String headline;
String tagController;
#override
_StundenplanBodyState createState() =>
_StundenplanBodyState(headline: headline, tagController: tagController);
}
class _StundenplanBodyState extends State<StundenplanBody> {
_StundenplanBodyState({required this.headline, required this.tagController});
String headline;
String tagController;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(headline),
),
body: ListView(
children: [
StundenElement(),
],
),
);
}
}
class StundenElement extends StatelessWidget {
const StundenElement({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Column(
children: [
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.black),
borderRadius: BorderRadius.circular(20),
),
child: Container(
padding: EdgeInsets.all(20),
child: Text("Test"),
),
),
SizedBox(
height: 5,
),
],
);
}
}
Thank you for your help in advance!
I'm using flutter and i'm completely a newbie with this framework. I'm trying to use the visibility widget to show and hide a Row.
I'm trying to use this widget when I declare the variable bool _isVisible = false in a stateful or stateless widget, but I have a problem when I want to show and hide the row() through a widget from another dart file. I don't know how to do it. To solve this problem i'm trying to create a dart file for create a function and variable bool _isVisible = false; so that all widgets can access but I am unable to use the bool variable and the function of this dart file in my widgets.
in this picture: ontap in the green circle i want the pink color all the row() with the rating and the button to be hidden.
A screenshot of the issue from my application
P.S: sorry for my english
This is the widget( AnimeMovieDialog ) with the rating section that i want to be hidden (or show) when user tap on the CardAnimeMovie widget.
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Tutorial by Woolha.com',
home: AnimeMovieDialog(),
debugShowCheckedModeBanner: false,
);
}
}
class AnimeMovieDialog extends StatefulWidget {
#override
_AnimeMovieDialogState createState() => _AnimeMovieDialogState();
}
class _AnimeMovieDialogState extends State<AnimeMovieDialog> {
double _rating = 1;
double count = 1;
bool _isVisible = true;
void _change() {
setState(() {
_isVisible = !_isVisible;
print("tap succes");
});
}
void _close() {
setState(() {
_isVisible = false;
});
}
#override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return SafeArea(
child: Visibility(
visible: _isVisible,
child: Stack(children: [
Container(
width: width,
height: height,
decoration: BoxDecoration(color: Color(0xffffff).withOpacity(0.6)),
),
Center(
child: SingleChildScrollView(
child: Container(
width: width / 1.05,
height: height / 1.2,
decoration: BoxDecoration(color: Color(0xff212529)),
child: Column(
children: [
Row(
children: [
Container(
width: width / 1.05,
height: 60,
decoration: BoxDecoration(color: Color(0xff212529)),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding:
const EdgeInsets.fromLTRB(4.0, 5, 35, 0),
child: GestureDetector(
onTap: () {
_close();
},
child: Container(
width: 65,
height: 45,
color: Colors.blue,
child: Icon(Icons.clear,
color: Colors.white)),
),
),
Container(
width: width / 2,
height: height / 2,
child: TextField(
cursorColor: Colors.orange,
style: TextStyle(
color: Colors.white,
),
maxLines: 1,
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.white)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.orange)),
border: UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.white)),
hintText: 'Rechercher',
hintStyle:
TextStyle(color: Colors.white),
)),
),
Padding(
padding:
const EdgeInsets.fromLTRB(15, 0, 8, 0),
child: Container(
child: Icon(Icons.search,
color: Colors.white)),
)
],
),
)
],
),
Row(
children: [
Container(
width: width / 1.05,
height: height / 1.5,
child: ListView(
children: [
CardAnimeMovie(),
CardAnimeMovie(),
CardAnimeMovie(),
CardAnimeMovie(),
CardAnimeMovie(),
CardAnimeMovie()
],
),
)
],
),
Row(children: [
Column(
children: [
Container(
width: width / 2,
height: height / 11.25,
color: null,
child: Row(
children: [
Padding(
padding: const EdgeInsets.fromLTRB(
25, 0, 0, 0),
child: GFRating(
onChanged: (value) {
setState(() {
_rating = value;
});
},
value: _rating,
size: 25,
color: Colors.orange,
borderColor: Colors.orange,
),
)
],
)),
],
),
Padding(
padding: const EdgeInsets.fromLTRB(35, 0, 8, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
width: width / 3,
height: height / 18,
decoration: BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(25.0),
topRight: Radius.circular(25.0),
bottomLeft: Radius.circular(25.0),
bottomRight: Radius.circular(25.0))),
child: TextButton(
style: TextButton.styleFrom(
primary: Colors.blue,
onSurface: Colors.red,
),
onPressed: null,
child: Text('Noter',
style: TextStyle(
color: Colors.white,
fontFamily: 'DBIcons',
fontSize: 17)),
),
),
],
),
)
])
],
)),
),
),
]),
),
);
}
}
This is the movie resume (green in the picture)
class CardAnimeMovie extends StatefulWidget {
#override
_CardAnimeMovieState createState() => _CardAnimeMovieState();
}
class _CardAnimeMovieState extends State<CardAnimeMovie> {
// bool _visible = false;
// void ratechange() {
// setState(() {
// _visible = !_visible;
// });
// }
#override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return Padding(
padding: const EdgeInsets.all(2.0),
child: GestureDetector(
onTap: () {
ratechange();
},
child: Container(
width: width / 5,
height: height / 3.2,
decoration: BoxDecoration(color: Color(0xff272824)),
child: Row(
children: [
Column(children: [
Container(
width: width / 2.1,
height: height / 3.2,
child: Image.network(
'https://image.noelshack.com/fichiers/2014/31/1406628082-btlbdfqiyaasamj.jpg',
fit: BoxFit.cover,
),
)
]),
Column(children: [
Container(
width: width / 2.15,
height: height / 3.2,
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: Colors.white, width: 0.5),
),
),
child: Padding(
padding: const EdgeInsets.fromLTRB(15, 5, 0, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Row(
children: [
Text(
'Titre : oeuvre',
style: TextStyle(
color: Colors.white,
fontFamily: 'DBIcons',
fontSize: 18,
),
)
],
),
SizedBox(
height: 0.5,
),
Row(
children: [
Text(
'Auteur : XXXX',
style: TextStyle(
color: Colors.white,
fontFamily: 'DBIcons',
fontSize: 18,
),
)
],
),
SizedBox(height: 7),
Row(
children: [
Container(
width: width / 2.5,
height: height / 5,
child: Text(
"Résume : Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries,",
style: TextStyle(
color: Colors.white,
fontFamily: 'DBIcons',
fontSize: 18,
),
),
)
],
)
],
),
),
)
])
],
)),
),
);
}
}
You can give function to another dart file and with this you can invoke function in another dart file.
For example:
class AnotherWidget extends StatelessWidget{
final Function myFunction;
AnotherWidget ({this.myFunction});
#override
Widget build(BuildContext context) {
return FlatButton(onPressed: myFunction,....);
}
I am currently developing an app which people can save their receipt in it, I shared home screen below,initial time It will be empty, as soon as user add new menu, it will get full with menu, After user added new menu, the should be able to click the menu container, and access to new screen for example, İn home screen I created container which called "CAKES", the cakes screen should be created, if I created another menu in my home screen It should also created too, I currently menu extanded screen as a statefull widget already, you can see below, but my question is How can I create this page for spesific menu's , How can I store them, in list, in map etc, Lastly, I dont want user information dissapear, I know I have to use database, but I want to use local database, How can I handle with that, Have a nice day...
import 'package:flutter/material.dart';
import 'package:lezzet_kitabi/add_menu_screen.dart';
import 'package:lezzet_kitabi/constants.dart';
import 'package:lezzet_kitabi/widgets.dart';
class HomeScreen extends StatefulWidget {
HomeScreen({this.newMenuName,this.imagePath});
final imagePath;
final newMenuName;
static String id="homeScreen";
#override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
Widget buildBottomSheet(BuildContext context)=>AddMenuScreen(buttonText: "Menü Ekle",route: HomeScreen,);
void initState(){
super.initState();
if (widget.newMenuName!=null && widget.imagePath!=null){
Widget newMenu=MenuCard(newMenuName: widget.newMenuName,imagePath: widget.imagePath);
menuCards.insert(0,newMenu);
}
}
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
backgroundColor: kColorTheme1,
appBar: AppBar(
centerTitle: true,
automaticallyImplyLeading: false,
elevation: 5,
backgroundColor: Color(0xFFF2C3D4).withOpacity(1),
title:TitleBorderedText(title:"SEVIMLI YEMEKLER", textColor: Color(0xFFFFFB00)),
actions: [
CircleAvatar(
radius: 27,
backgroundColor: Colors.transparent,
backgroundImage: AssetImage(kCuttedLogoPath),
),
],
),
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(kBGWithLogoOpacity),
fit: BoxFit.cover,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: GridView.count(
crossAxisCount: 2,
children:menuCards,
),
),
Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: EdgeInsets.all(10),
child: Container(
decoration: BoxDecoration(
boxShadow:[
BoxShadow(
color: Colors.black.withOpacity(1),
spreadRadius: 2,
blurRadius: 7,
offset: Offset(0,4),
),
],
color: kColorTheme7,
borderRadius: BorderRadius.circular(40),
),
child: FlatButton(
onPressed: (){
showModalBottomSheet(
context: context,
builder: (BuildContext context)=> AddMenuScreen(buttonText: "Menü Ekle",route: "homeScreen",),
);
},
child: TitleBorderedText(title: "LEZZET GRUBU EKLE",textColor: Colors.white,)
),
),
),
],
)
],
),
),
),
);
}
}
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:lezzet_kitabi/screens/home_screen.dart';
import 'package:lezzet_kitabi/widgets.dart';
import 'constants.dart';
import 'dart:math';
class AddMenuScreen extends StatefulWidget {
AddMenuScreen({#required this.buttonText, #required this.route});
final route;
final String buttonText;
static String id="addMenuScreen";
#override
_AddMenuScreenState createState() => _AddMenuScreenState();
}
class _AddMenuScreenState extends State<AddMenuScreen> {
int selectedIndex=-1;
Color _containerForStickersInactiveColor=Colors.white;
Color _containerForStickersActiveColor=Colors.black12;
final stickerList= List<String>.generate(23, (index) => "images/sticker$index");
String chosenImagePath;
String menuName;
int addScreenImageNum;
void initState(){
super.initState();
createAddScreenImageNum();
}
void createAddScreenImageNum(){
Random random =Random();
addScreenImageNum = random.nextInt(3)+1;
}
#override
Widget build(BuildContext context) {
return Material(
child: Container(
color: kColorTheme9,
child: Container(
height: 400,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(topRight: Radius.circular(40),topLeft: Radius.circular(40)),
),
child:Padding(
padding:EdgeInsets.all(20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
decoration: BoxDecoration(
color: kColorTheme2,
borderRadius: BorderRadius.circular(90)
),
child: TextField(
style: TextStyle(
color: Colors.black,
fontFamily:"Graduate",
fontSize: 20,
),
textAlign: TextAlign.center,
onChanged: (value){
menuName=value;
},
decoration: InputDecoration(
border:OutlineInputBorder(
borderRadius: BorderRadius.circular(90),
borderSide: BorderSide(
color: Colors.teal,
),
),
hintText: "Menü ismi belirleyin",
hintStyle: TextStyle(
color: Colors.black.withOpacity(0.2),
fontFamily: "Graduate",
),
),
),
),
SizedBox(height: 20,),
Text(" yana kadırarak menünüz icin bir resim secin",textAlign: TextAlign.center,
style: TextStyle(fontFamily: "Graduate", fontSize: 12),),
SizedBox(height: 20,),
Expanded(
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: stickerList.length,
itemBuilder: (context,index){
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: index == selectedIndex ?
_containerForStickersActiveColor :
_containerForStickersInactiveColor,
),
child:FlatButton(
child: Image(
image: AssetImage("images/sticker$index.png"),
),
onPressed: (){
setState(() {
selectedIndex = index;
});
},
),
);
}
),
),
SizedBox(height: 20,),
Container(
decoration: BoxDecoration(
border: Border.all(style: BorderStyle.solid),
color: kColorTheme7,
borderRadius: BorderRadius.circular(90),
),
child: FlatButton(
onPressed: (){
widget.route=="homeScreen"?Navigator.push(context, MaterialPageRoute(builder: (context)=>HomeScreen(newMenuName: menuName,imagePath: "images/sticker$selectedIndex.png")))
:Navigator.push(context, MaterialPageRoute(builder: (context)=>MenuExtension(menuExtensionName: menuName)),
);
},
child: Text(widget.buttonText, style: TextStyle(fontSize: 20, color: Colors.white,
fontFamily: "Graduate", fontWeight: FontWeight.bold),),
),
),
],
),
),
),
),
);
}
}
import 'package:flutter/material.dart';
import 'dart:math';
import 'add_menu_screen.dart';
import 'package:bordered_text/bordered_text.dart';
import 'package:lezzet_kitabi/screens/meal_screen.dart';
import 'constants.dart';
List<Widget> menuExtensionCards=[EmptyMenu()];
List<Widget> menuCards=[EmptyMenu()];
class MenuCard extends StatelessWidget {
MenuCard({this.newMenuName, this.imagePath});
final newMenuName;
final imagePath;
#override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.only(top:15.0),
child: FlatButton(
onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context)=>MenuExtension(menuExtensionName: newMenuName,)));
},
child: Container(
height: 180,
width: 180,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Color((Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(0.5),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(height: 10,),
Container(
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.5),
borderRadius: BorderRadius.circular(90),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
newMenuName,
style: TextStyle(
color: Colors.black,
fontSize: 20,
fontFamily: 'Graduate',
fontWeight: FontWeight.bold),
),
),
),
Expanded(
child: Padding(
padding:EdgeInsets.all(5),
child: Image(
image: AssetImage(
imagePath
),
),
),
),
],
),
),
),
);
}
}
class EmptyMenu extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.only(top:15.0),
child: FlatButton(
onPressed: (){
showModalBottomSheet(
context: context,
builder: (BuildContext context)=> AddMenuScreen(buttonText: "Menü Ekle",route:"homeScreen"),
);
},
child: Container(
height: 180,
width: 180,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.black12.withOpacity(0.1),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(Icons.add_circle_outline_outlined,size: 100,color: Colors.grey.shade400,),
],
),
),
),
);
}
}
class MenuExtension extends StatefulWidget {
MenuExtension({this.menuExtensionName});
final String menuExtensionName;
#override
_MenuExtensionState createState() => _MenuExtensionState();
}
class _MenuExtensionState extends State<MenuExtension> {
Widget buildBottomSheet(BuildContext context)=>AddMenuScreen(buttonText: "Tarif Ekle",route: MealScreen,);
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(
centerTitle: true,
automaticallyImplyLeading: false,
elevation: 5,
backgroundColor: Color(0xFFF2C3D4).withOpacity(1),
title:BorderedText(
child:Text(
widget.menuExtensionName,
style: TextStyle(
color: Color(0XFFFFFB00),
fontSize: 30,
fontFamily: "Graduate"
),
),
strokeWidth: 5,
strokeColor: Colors.black,
),
actions: [
CircleAvatar(
radius: 27,
backgroundColor: Colors.transparent,
backgroundImage: AssetImage("images/cuttedlogo.PNG"),
),
],
),
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("images/logoBGopacity.png"),
fit: BoxFit.cover,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: GridView.count(
crossAxisCount: 2,
children:menuExtensionCards,
),
),
Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: EdgeInsets.all(10),
child: Container(
decoration: BoxDecoration(
boxShadow:[
BoxShadow(
color: Colors.black.withOpacity(1),
spreadRadius: 2,
blurRadius: 7,
offset: Offset(0,4),
),
],
color: kColorTheme7,
borderRadius: BorderRadius.circular(40),
),
child: FlatButton(
onPressed: (){
showModalBottomSheet(
context: context,
builder: (BuildContext context)=> AddMenuScreen(buttonText: "Tarif Ekle", route:"mealScreen"),
);
},
child: BorderedText(
strokeWidth: 5,
strokeColor: Colors.black,
child:Text("Tarif Ekle",style: TextStyle(
color: Colors.white,
fontFamily:'Graduate',
fontSize:30,
),
),
),
),
),
),
],
)
],
),
),
),
);
}
}
class TitleBorderedText extends StatelessWidget {
TitleBorderedText({this.title, this.textColor});
final Color textColor;
final String title;
#override
Widget build(BuildContext context) {
return BorderedText(
strokeWidth: 5,
strokeColor: Colors.black,
child:Text(title,style: TextStyle(
color: textColor,
fontFamily:'Graduate',
fontSize:30,
),
),
);
}
}
import 'package:flutter/material.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:url_launcher/url_launcher.dart';
class HomeScreen extends StatefulWidget {
#override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
int _currentIndex = 0;
List cardList = [Item1(), Item2(), Item3(), Item4()];
List<T> map<T>(List list, Function handler) {
List<T> result = [];
for (var i = 0; i < list.length; i++) {
result.add(handler(i, list[i]));
}
return result;
}
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Card Carousel App',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: SafeArea(
child: Scaffold(
resizeToAvoidBottomPadding: false,
appBar: AppBar(
title: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Image(
image: AssetImage('assets/liberta.jpeg'),
width: 120,
),
Text(
'Libertà&Ricchezza',
style: TextStyle(color: Colors.black),
)
],
),
backgroundColor: Colors.white,
),
body: SingleChildScrollView(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
image: DecorationImage(
image: AssetImage('assets/background.jpeg'),
fit: BoxFit.cover,
)
),
child: Column(
children: <Widget>[
SizedBox(
height: 10,
),
CarouselSlider(
options: CarouselOptions(
height: 240.0,
autoPlay: true,
autoPlayInterval: Duration(seconds: 3),
autoPlayAnimationDuration: Duration(milliseconds: 800),
autoPlayCurve: Curves.fastOutSlowIn,
pauseAutoPlayOnTouch: true,
aspectRatio: 2.0,
onPageChanged: (index, reason) {
setState(() {
_currentIndex = index;
});
},
),
items: cardList.map((card) {
return Builder(builder: (BuildContext context) {
return Container(
height: MediaQuery.of(context).size.height * 0.30,
width: MediaQuery.of(context).size.width,
child: Card(
color: Colors.blueAccent,
child: card,
),
);
});
}).toList(),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: map<Widget>(cardList, (index, url) {
return Container(
width: 10.0,
height: 10.0,
margin:
EdgeInsets.symmetric(vertical: 10.0, horizontal: 2.0),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: _currentIndex == index
? Colors.white
: Colors.grey,
),
);
}),
),
SizedBox(
height: 20,
),
Row(
children: [
Expanded(
child: Container(
height: 85,
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Color(0xff024f9c),
),
child: Center(
child: Text(
"L&R PER LA PERSONA",
style: TextStyle(
color: Colors.white,
fontSize:20,
fontWeight: FontWeight.bold
),
textAlign: TextAlign.center,
),
),
)),
],
),
Row(
children: [
Expanded(
child: GestureDetector(
onTap: () {
setState(() {
Navigator.pushNamed(context, '/persona');
});
},
child: Container(
height: 85,
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Color(0xff9c0202),
),
child: Center(
child: Text(
"L&R PER L'AZIENDA",
style: TextStyle(
color: Colors.white,
fontSize:20,
fontWeight: FontWeight.bold
),
textAlign: TextAlign.center,
),
),
)),
),
],
)
],
),
),
),
),
));
}
}
class Item1 extends StatelessWidget {
const Item1({Key key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
child: InkWell(
child: Image(
image: AssetImage('assets/mandela.jpeg'),
fit: BoxFit.cover,
),
onTap: () => launch('https://www.instagram.com/libertaericchezza/'),
),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
stops: [
0.3,
1
],
colors: [
Color(0xffff4000),
Color(0xffffcc66),
]),
),
);
}
}
class Item2 extends StatelessWidget {
const Item2({Key key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
child:InkWell(
child: Image(
image: AssetImage('assets/astronauta.jpeg'),
fit: BoxFit.cover,
),
onTap: () => launch('https://www.instagram.com/libertaericchezza/'),
),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
stops: [
0.3,
1
],
colors: [
Color(0xffff4000),
Color(0xffffcc66),
]),
),
);
}
}
class Item3 extends StatelessWidget {
const Item3({Key key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
child:InkWell(
child: Image(
image: AssetImage('assets/farfalle.jpeg'),
fit: BoxFit.cover,
),
onTap: () => launch('https://www.instagram.com/libertaericchezza/'),
),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
stops: [
0.3,
1
],
colors: [
Color(0xffff4000),
Color(0xffffcc66),
]),
),
);
}
}
class Item4 extends StatelessWidget {
const Item4({Key key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
child: InkWell(
child: Image(
image: AssetImage('assets/car.jpeg'),
fit: BoxFit.cover,
),
onTap: () => launch('https://www.instagram.com/libertaericchezza/'),
),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
stops: [
0.3,
1
],
colors: [
Color(0xffff4000),
Color(0xffffcc66),
]),
),
);
}
}
I have insert a background image but there is a white space on the bottom and i don-t understand why, i try the resizedToAVoidBottomPadding but doesn-t work,I have insert a background image but there is a white space on the bottom and i don-t understand why, i try the resizedToAVoidBottomPadding but doesn-t workI have insert a background image but there is a white space on the bottom and i don-t understand why, i try the resizedToAVoidBottomPadding but doesn-t work
Have you try remove bottom safearea, safearea will occupy both top and bottom for notch and control area:
SafeArea(
bottom: false,
Why do buttons in Flutter tend to align their children to the centre when they are placed in list views?
For example:
import 'package:flutter/material.dart';
class Test extends StatefulWidget {
#override
_TestState createState() => _TestState();
}
class _TestState extends State<Test> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: ListView.builder(
itemCount: 10,
itemBuilder: (context, index){
return MaterialButton(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Hello"),
],
));
}
),
);
}
}
This would result in ten hellos spaced evenly by the default height of the button, but they would be centered; even though I used the CrossAxisAlignment.start property in a column.
Here is the image:
But when I replace the MaterialButton with a Container they are aligned to the start to the column as wanted.
When I just remove the ListView.Builder I get 'hello' aligned to the start.
The same thing happens with the rest of the buttons.
Is there a way to make buttons in list views not have centered children inside them?
Edit: the example was fixed by #Harry but it didn't fix my exact code
here is my code: I try to created a list of widgets outside and use a function to add my list items into that list and return a list view through the ActivitiesList widget
import 'package:flutter/material.dart';
import 'package:list_them_out/models/activities.dart';
import 'package:provider/provider.dart';
class ActivitiesList extends StatefulWidget {
#override
_ActivitiesListState createState() => _ActivitiesListState();
}
double conBorderRadius = 30;
class _ActivitiesListState extends State<ActivitiesList> {
List<Widget> itemData = [];
void getData(context) {
double cardHeight = MediaQuery.of(context).size.height * 0.3;
double cardWidth = MediaQuery.of(context).size.width * 0.97;
final activities = Provider.of<List<Activity>>(context);
activities == null
// ignore: unnecessary_statements
? null
: setState(() {
itemData = [];
});
activities == null
// ignore: unnecessary_statements
? null
: setState(() {
activities.forEach((element) {
itemData.add(Padding(
padding: EdgeInsets.symmetric(horizontal: 10),
child: Container(
width: cardWidth,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(conBorderRadius),
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: <Color>[
Colors.lightGreen[300],
Colors.lightBlue[300],
]
),
boxShadow: [
BoxShadow(
color: Colors.grey[600],
offset: Offset(4.0, 4.0),
blurRadius: 15,
spreadRadius: 1),
BoxShadow(
color: Colors.white,
offset: Offset(-4.0, -4.0),
blurRadius: 15,
spreadRadius: 1),
]),
child: Stack(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(conBorderRadius),
child: MaterialButton(
splashColor: HSLColor.fromColor(Colors.green).toColor(),
onPressed: () {},
child: Align(
alignment: Alignment.centerLeft,
child: Container(
child: Padding(
padding: EdgeInsets.only(top: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: cardWidth * 0.61,
child: Text(
element.name,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.grey[600],
fontSize: 25,
fontWeight: FontWeight.w500,
letterSpacing: 1,
),
),
),
Padding(
padding: EdgeInsets.only(top: cardHeight * 0.09, left: cardWidth * 0.03),
child: Container(
width: cardWidth * 0.48,
child: RichText(
maxLines: 2,
overflow: TextOverflow.ellipsis,
text: TextSpan(children: [
TextSpan(
text: "Start: ",
style: TextStyle(
color: Colors.grey[800],
fontSize: 20,
fontWeight: FontWeight.w400,
letterSpacing: 1),
),
TextSpan(
text: element.time,
style: TextStyle(
color: Colors.black87,
fontWeight: FontWeight.w300,
fontSize: 20,
))
]),
),
),
),
SizedBox(height: cardHeight * 0.06,),
Row(
children: [
IconButton(icon: Icon(Icons.comment),
onPressed: () => null,
color: Colors.grey[600],
),
Padding(
padding: EdgeInsets.only(bottom: 5),
child: Text("Comments", style: TextStyle(color: Colors.grey[600], fontSize: 20, fontWeight: FontWeight.w300, letterSpacing: 1),),
)
],
)
],
),
),),
),
),
),
Positioned(
right: 0,
bottom: 0,
top: 0,
child: ClipPath(
clipper: MyClip(radius: conBorderRadius),
child: Container(
height: cardHeight,
width: cardWidth * 0.45,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: <Color>[
Colors.grey[300],
Colors.lightBlue[100].withOpacity(0.5)
])),
),
),
),
Positioned(
right: cardWidth * 0.05,
bottom: 20,
child: Container(
child: Text("Hello"),
),
)
],
)),
));
});
});
}
#override
Widget build(BuildContext context) {
double listHeight = MediaQuery.of(context).size.height * 0.86;
double listWidth = MediaQuery.of(context).size.width * 0.97;
getData(context);
return ClipRRect(
borderRadius: BorderRadius.only(
topRight: Radius.circular(50), topLeft: Radius.circular(50)),
child: Container(
height: listHeight,
width: listWidth,
child: ListView.builder(
itemCount: itemData.length,
itemBuilder: (context, index) {
return Padding(
padding: EdgeInsets.only(bottom: 30),
child: itemData[index],
);
}),
));
}
}
``
Try using the Align widget. Just wrap the column with an align widget and have the alignment parameter be alignment.centerLeft.
import 'package:flutter/material.dart';
class Test extends StatefulWidget {
#override
_TestState createState() => _TestState();
}
class _TestState extends State<Test> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: ListView.builder(
itemCount: 10,
itemBuilder: (context, index){
return MaterialButton(
child: Align(
child:Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Hello"),
],
),
alignment: Alignment.centerLeft,
)
);
}
),
);
}
}