I currently have a page with an image like this, but I want to add an svg image to the button section at the bottom as in the second image. How can I do it?
İmages
My Code :
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'URL Shortener',
theme: ThemeData(
primarySwatch: Colors.purple,
),
home: StartPage(),
);
}
}
class StartPage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[300],
body: Center(
child: ListView(
children: [
Center(
child: Text(
"Shortly",
style: TextStyle(
fontSize: 40,
height: 2.0,
color: Color.fromRGBO(53, 50, 62, 10),
fontWeight: FontWeight.bold),
),
),
SvgPicture.asset(
'assets/illustration.svg',
),
Center(
child: Text(
"Let's get started!",
style: TextStyle(
fontSize: 20,
color: Color.fromRGBO(53, 50, 62, 10),
fontWeight: FontWeight.bold),
),
),
Center(
child: SizedBox(
width: 200,
height: 60,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Paste your first link into the field to shorten it",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
color: Color.fromRGBO(76, 74, 85, 10),
fontWeight: FontWeight.bold)),
),
),
),
Center(
child: SizedBox(
width: 300,
height: 40,
child: TextField(
textAlign: TextAlign.center,
decoration: InputDecoration(
contentPadding: EdgeInsets.all(10.0),
border: OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
borderSide: BorderSide(
width: 0,
style: BorderStyle.none,
),
),
fillColor: Colors.white,
filled: true,
hintText: 'Shorten a link here ...'),
),
),
),
Center(
child: SizedBox(
width: 300,
child: ElevatedButton(
onPressed: () {
print("Button Click");
},
style: ElevatedButton.styleFrom(
primary: Colors.blue,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
minimumSize: Size(60, 40),
),
child: Text('SHORTEN IT!'),
),
),
)
],
),
));
}
}
Hello, I currently have a page with an image like this, but I want to add an svg image to the button section at the bottom as in the second image. How can I do it?
Demo Widget
class StartPage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[300],
body: ListView(
children: [
Center(
child: Text(
"Shortly",
style: TextStyle(
fontSize: 40,
height: 2.0,
color: Color.fromRGBO(53, 50, 62, 10),
fontWeight: FontWeight.bold),
),
),
// SvgPicture.asset(
// 'assets/illustration.svg',
// ),
Container(
height: 200,
color: Colors.deepPurple.withOpacity(.3),
child: Text("SVG assets here"),
),
Center(
child: Text(
"Let's get started!",
style: TextStyle(
fontSize: 20,
color: Color.fromRGBO(53, 50, 62, 10),
fontWeight: FontWeight.bold),
),
),
Center(
child: SizedBox(
width: 200,
height: 60,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Paste your first link into the field to shorten it",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
color: Color.fromRGBO(76, 74, 85, 10),
fontWeight: FontWeight.bold)),
),
),
),
SizedBox(
/// bottombackground height
height: 220,
child: Stack(
alignment: Alignment.center,
children: [
/// background svg asset
Container(
color: Colors.deepOrange.withOpacity(.4),
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: 300,
height: 40,
child: TextField(
textAlign: TextAlign.center,
decoration: InputDecoration(
contentPadding: EdgeInsets.all(10.0),
border: OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
borderSide: BorderSide(
width: 0,
style: BorderStyle.none,
),
),
fillColor: Colors.white,
filled: true,
hintText: 'Shorten a link here ...'),
),
),
/// a little space between buttons
SizedBox(
height: 10,
),
SizedBox(
width: 300,
child: ElevatedButton(
onPressed: () {
print("Button Click");
},
style: ElevatedButton.styleFrom(
primary: Colors.blue,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
minimumSize: Size(60, 40),
),
child: Text('SHORTEN IT!'),
),
),
],
),
],
),
),
],
),
);
}
}
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[300],
body: Center(
child: Container(
height:MediaQuery.of(context).size.height,
width:MediaQuery.of(context).size.width,
child: Stack(
children: [
SvgPicture.asset(
"assets/a.svg",
fit: BoxFit.fill,
),
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween ,
children: [
Center(
child: Container(
margin: EdgeInsets.only(top:20.0),
child: Text(
"Shortly",
style: TextStyle(
fontSize: 40,
height: 2.0,
color: Color.fromRGBO(53, 50, 62, 10),
fontWeight: FontWeight.bold),
),
),
),
Column(
children: [
Center(
child: Container(
margin: EdgeInsets.only(top:200.0),
child: Text(
"Let's get started!",
style: TextStyle(
fontSize: 20,
color: Color.fromRGBO(53, 50, 62, 10),
fontWeight: FontWeight.bold),
),
),
),
Center(
child: SizedBox(
width: 200,
height: 60,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Paste your first link into the field to shorten it",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
color: Color.fromRGBO(76, 74, 85, 10),
fontWeight: FontWeight.bold)),
),
),
),
],
),
Container(
height: 150.0,
color: Colors.purple,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(
child: Container(
width: 300,
height: 40,
child: TextField(
textAlign: TextAlign.center,
decoration: InputDecoration(
contentPadding: EdgeInsets.all(10.0),
border: OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
borderSide: BorderSide(
width: 0,
style: BorderStyle.none,
),
),
fillColor: Colors.white,
filled: true,
hintText: 'Shorten a link here ...'),
),
),
),
Center(
child: SizedBox(
width: 300,
child: ElevatedButton(
onPressed: () {
print("Button Click");
},
style: ElevatedButton.styleFrom(
primary: Colors.blue,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
minimumSize: Size(60, 40),
),
child: Text('SHORTEN IT!'),
),
),
),
],
),
)
],
),
],
),
),
));
}
Related
import 'package:flutter/material.dart';
import 'package:smart_uild/assets.dart';
class Myprofile extends StatelessWidget {
const Myprofile({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: const Color(0xff384A62),
leading: IconButton(
icon: const Icon(Icons.arrow_back, color: Colors.white),
onPressed: () => Navigator.of(context).pop(),
),
title: const Text("My Profile"),
elevation: 0,
),
body: Padding(
padding: const EdgeInsets.only(
left: 18.0,
top: 18,
),
child: Card(
color: Colors.grey[900],
shape: RoundedRectangleBorder(
side: const BorderSide(color: Color(0xff384A62), width: 1),
borderRadius: BorderRadius.circular(10),
),
child: Container(
width: 350,
height: 151,
color: Colors.white,
child: Row(
children: [
Center(
child: Padding(
padding: const EdgeInsets.all(10),
child: Expanded(
child: Image.asset(
image1,
width: 100,
height: 100,
),
flex: 2,
),
),
),
Expanded(
child: Container(
alignment: Alignment.topLeft,
child: Padding(
padding: const EdgeInsets.only(top: 38.0),
child: Column(
children: [
const Expanded(
flex: 5,
child: ListTile(
title: Text(
"Genova",
style: TextStyle(
color: Color(0xff384A62),
fontSize: 20,
fontWeight: FontWeight.w400),
),
),
),
Expanded(
flex: 5,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
const SizedBox(
width: 8,
),
TextButton.icon(
style: TextButton.styleFrom(
textStyle:
const TextStyle(color: Colors.white),
backgroundColor: const Color(0xffFF0000),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6.0),
),
),
onPressed: () => {},
icon: const Icon(
Icons.power_off,
color: Colors.white,
),
label: const Text(
'DUTY SIGN OFF',
style: TextStyle(
color: Colors.white,
fontSize: 14,
fontWeight: FontWeight.w400),
),
),
const SizedBox(
width: 8,
),
],
),
),
const SizedBox(
width: 8,
),
],
),
),
),
),
],
),
),
elevation: 0,
margin: const EdgeInsets.all(10),
),
),
);
}
}
Is there any plugin in Flutter which could achieve something like the profile picture preview of persons who liked the picture on Instagram?
There is no plugin but you can make a custom one using circle avatars(with white border) in a stack.
class CustomAvatars extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container(
width: 80,
height: 40,
color: Colors.white,
child: Stack(
children: <Widget>[
Align(
alignment: Alignment.centerRight,
child: CircleAvatar(
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 18,
backgroundColor: Colors.red,
child: Image.asset('assets\image'), // Provide your custom image
),
),
),
Align(
alignment: Alignment.center,
child: CircleAvatar(
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 18,
backgroundColor: Colors.red,
child: Image.asset('assets\image'), // Provide your custom image
),
),
),
Align(
alignment: Alignment.centerLeft,
child: CircleAvatar(
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 18,
backgroundColor: Colors.red,
child: Image.asset('assets\image'), // Provide your custom image
),
),
),
],
),
);
}
}
Or you can use Align inside of ListView(); widget
Widget _stackedHeads() => Container(
width: double.infinity,
height: 100,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 4,
itemBuilder: (context, index) {
return Align(
widthFactor: 0.6,
child: CircleAvatar(
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 18,
backgroundImage: NetworkImage(
'https://www.jessleewong.com/wp-content/uploads/2019/12/jessleewong_20191109_3.jpg'), // Provide your custom image
),
),
);
}));
cames in handy when your content is dynamic, in that code in Align(); widget property widthFactor: determines how much in horizontal they should overlap.
You could try my package (signed_spacing_flex). It's exactly the same as a normal Row (or Column and Flex). But it also lets you set negative spacing which causes its children to overlap. You can also set which children should be on top when they overlap.
In your case it would be something like:
const imageURL = "https://upload.wikimedia.org/wikipedia/commons/thumb/9/95/Instagram_logo_2022.svg/150px-Instagram_logo_2022.svg.png";
SignedSpacingRow(
spacing: -16.0,
stackingOrder: StackingOrder.firstOnTop,
children: const [
CircleAvatar(
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 18,
backgroundImage: NetworkImage(imageURL),
),
),
CircleAvatar(
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 18,
backgroundImage: NetworkImage(imageURL),
),
),
CircleAvatar(
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 18,
backgroundImage: NetworkImage(imageURL),
),
),
],
),
It also works with expanded children if you need.
There is no plugin but you can make a custom one using circle avatars and positioned in a stack.
import 'package:flutter/material.dart';
class CustomAvatar extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container(
width: 80,
height: 40,
color: Colors.white,
child: Stack(
children: <Widget>[
Positioned(
left: 0,
child: CircleAvatar(
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 18,
backgroundColor: Colors.red,
child: Image.asset('assets\image'), // Provide your custom image
),
),
),
Positioned(
left: 8,
child: CircleAvatar(
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 18,
backgroundColor: Colors.red,
child: Image.asset('assets\image'), // Provide your custom image
),
),
),
Positioned(
left: 16,
child: CircleAvatar(
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 18,
backgroundColor: Colors.red,
child: Image.asset('assets\image'), // Provide your custom image
),
),
),
],
),
);
}
}
it is my signup.dart file code:
it is nothing show somthing like a error.
But just i would like to see display an error under of textfield but it doesn't show anything.
Can anyone say what I'm doing wrongly?
import 'package:flutter/material.dart';
class SignupPage extends StatefulWidget {
#override
_SignupPageState createState() => _SignupPageState();
}
class _SignupPageState extends State<SignupPage> {
final formkey = new GlobalKey<FormState>();
registered() {
print("validation form...$formkey");
}
#override
Widget build(BuildContext context) {
return new Scaffold(
resizeToAvoidBottomPadding: false,
body: Column(crossAxisAlignment: CrossAxisAlignment.start, children: <
Widget>[
Container(
child: Stack(
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(15.0, 110.0, 0.0, 0.0),
child: Text(
'Qeydiyyat',
style:
TextStyle(fontSize: 60.0, fontWeight: FontWeight.bold),
),
),
],
),
),
SizedBox(height: 30.0),
Container(
padding: EdgeInsets.only(top: 35.0, left: 20.0, right: 20.0),
child: Form(
key: formkey,
child: Column(
children: <Widget>[
TextFormField(
decoration: InputDecoration(
labelText: 'E-Poçt',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
// hintText: 'EMAIL',
// hintStyle: ,
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green))),
validator: (val) {
return "sea";
},
),
SizedBox(height: 10.0),
TextFormField(
keyboardType: TextInputType.text,
decoration: InputDecoration(
labelText: 'Şifrə ',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green))),
obscureText: true,
validator: (val) {
return "sea";
},
),
SizedBox(height: 10.0),
TextFormField(
decoration: InputDecoration(
labelText: 'Ad Soyad',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green))),
validator: (val) {
return "sea";
},
),
SizedBox(height: 50.0),
Container(
height: 40.0,
child: RaisedButton(
color: Colors.blue,
onPressed: registered,
shape: RoundedRectangleBorder(
side: BorderSide(color: Colors.blue),
borderRadius: BorderRadius.circular(50),
),
child: Center(
child: Text(
'Qeydiyyat',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat'),
),
),
)),
SizedBox(height: 20.0),
Container(
height: 40.0,
child: RaisedButton(
color: Colors.red,
disabledColor: Colors.transparent,
shape: RoundedRectangleBorder(
side: BorderSide(color: Colors.blue),
borderRadius: BorderRadius.circular(50),
),
child: InkWell(
onTap: () {
Navigator.of(context).pop();
},
child: Center(
child: Text('Daxil ol',
style: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat')),
),
),
),
),
],
),
)),
]));
}
}
it is nothing show somthing like a error.
But just i would like to see display an error under of textfield but it doesn't show anything.
Can anyone say what I'm doing wrongly?
if you want to validation work automatically set autoValidate property of TextField to true. otherwise, if you want to validate after an event such button clicks you can call validate() method. your register method can change to something like this:
registered() {
if (formKey.currentState.validate()) {
//do something
}
}
I have often found really quick and very competent help here. And hope you can help me again.
I have had an error message for three days, which I cannot get solved.
I explained the problem to you in a small video.
The link to the video is: "https://drive.google.com/file/d/1T9uOnEaNp5W6_kcO6eV9o64Fp3sRkB3f/view?usp=sharing"
I really hope you see the mistake I don't see!
This is the code of the Foodcard, which according to Flutter should cause the error:
The method '-' was called on null.
Receiver: null
Tried calling: -(30.0)
The relevant error-causing widget was:
FoodCard file:///C:/Users/stefa/AndroidStudioProjects/cronum_app_web%20-%20Kopie/lib/Components/ProviderComponents.dart:298:9
FoodCard:
class FoodCard extends StatelessWidget {
FoodCard({
#required this.description,
#required this.imagePath,
#required this.price,
#required this.foodName,
#required this.foodItem,
#required this.increaseCallback,
#required this.decreaseCallback,
this.count = 0,
});
final double radius = 40;
static double listViewHeight;
final double margin = 15;
final double containerHeight = 130;
final int count;
final String imagePath;
final String foodName;
final String price;
final String description;
final FoodItem foodItem;
final Function increaseCallback;
final Function decreaseCallback;
#override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 10, vertical: margin),
width: 220,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(radius),
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.topRight,
colors: ([
gradientColor1.withOpacity(opacityOfHeader),
primaryColor.withOpacity(opacityOfHeader),
gradientColor2.withOpacity(opacityOfHeader),
]),
),
boxShadow: [
BoxShadow(
blurRadius: 8,
color: Colors.black.withOpacity(0.3),
offset: Offset(5, 5),
),
],
color: Colors.white,
),
child: Column(
children: <Widget>[
Stack(
alignment: Alignment.center,
children: <Widget>[
Column(
children: <Widget>[
SizedBox(
height: listViewHeight - margin * 2 - containerHeight,
),
Container(
height: containerHeight,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(radius),
topRight: Radius.circular(radius),
bottomLeft: Radius.circular(radius),
bottomRight: Radius.circular(radius),
),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.2),
offset: Offset(0, -5),
blurRadius: 8)
],
color: Colors.white),
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 40),
child: Center(
child: Text(
foodName,
style: TextStyle(
color: Colors.black,
fontSize: 17,
fontWeight: FontWeight.w900,
),
),
),
),
Padding(
padding: EdgeInsets.symmetric(
horizontal: 20, vertical: 15),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailPage(
foodItem: foodItem,
increaseCount: increaseCallback,
decreaseCount: decreaseCallback,
),
),
);
},
child: Container(
height: 30,
width: 80,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
offset: Offset(5, 5),
color: Colors.black.withOpacity(0.3),
blurRadius: 8)
],
color: buttonColor,
borderRadius: BorderRadius.circular(25),
),
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 7, vertical: 5),
child: Center(
child: Text(
'Details',
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
),
),
),
Container(
color: Colors.grey.withOpacity(0.5),
height: 25,
width: 1,
),
Container(
height: 30,
width: 80,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25),
color: buttonColor,
boxShadow: [
BoxShadow(
blurRadius: 8,
color: Colors.black.withOpacity(0.3),
offset: Offset(5, 5),
),
],
),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceAround,
children: <Widget>[
InkWell(
onTap: decreaseCallback,
child: Container(
height: 22,
width: 22,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(5),
color: buttonColor,
),
child: Center(
child: Icon(
Icons.remove,
color: Colors.white,
size: 22,
),
),
),
),
Text(
count.toString(),
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.w900,
),
),
InkWell(
onTap: increaseCallback,
child: Container(
height: 22,
width: 22,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(15),
color: Colors.white,
),
child: Center(
child: Icon(
Icons.add,
color: buttonColor,
size: 22,
),
),
),
),
],
),
),
],
),
),
],
),
),
],
),
Positioned(
top: 30,
child: InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailPage(
foodItem: foodItem,
increaseCount: increaseCallback,
decreaseCount: decreaseCallback,
),
),
);
},
child: Image(
height: listViewHeight / 2,
width: listViewHeight / 2,
image: AssetImage(imagePath),
),
),
),
],
)
],
),
);
}
If it is not because of the FoodCard, the function with which I create the list of Foodcards could also be the problem.
I am amazed by the error message because it is so extremely non-specific. Before I automated the creation of the list, everything worked wonderfully.
List<Widget> buildEntdeckenCards() {
List<Widget> foodCardList = [];
for (FoodItem foodItem in top10) {
print(foodItem.foodName);
foodCardList.add(
FoodCard(
description: foodItem.description,
foodName: foodItem.foodName,
foodItem: foodItem,
price: foodItem.price,
imagePath: foodItem.imagePath,
decreaseCallback: () {
decreaseCount(foodItem);
},
increaseCallback: () {
increaseCount(foodItem);
},
),
);
}
return foodCardList;
}
I think your listViewHeight variable is null, and you are trying to use it in expression
SizedBox(height: listViewHeight - margin * 2 - containerHeight,),
I think that's why you see the following error The method '-' was called on null. Assign some value to listViewHeight before using it.
I have a for Loop where articles get loaded into a Widget and I only want one to be enabled, so how can I do that?
So far I got it working, but it doesn't recognise if I pressed another Button and I am relatively new to Flutter so I don't exactly know how I can implement such a feature.
Widget for Articles
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:wiegon/icons/nuleo_icons.dart';
import 'package:wiegon/main.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:wiegon/pages/control_screen.dart';
import 'package:wiegon/widgets/widgets.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
import 'package:page_transition/page_transition.dart';
class ArticleandAmount extends StatelessWidget {
#override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
leading: Builder(
builder: (BuildContext context) {
return IconButton(
icon: new SvgPicture.asset(wiegonLogo,
allowDrawingOutsideViewBox: true,
semanticsLabel: 'Wiegon Logo'),
onPressed: null,
);
},
),
title: Text(
"Artikel und Menge",
style: TextStyle(fontSize: 18, color: Color(0xffFDFEFE)),
),
backgroundColor: Color(0xff466988),
),
body: Articleamount(),
endDrawer: Enddrawer());
}
}
class Articleamount extends StatefulWidget {
#override
_ArticleamountState createState() {
return _ArticleamountState();
}
}
String displayedWeight;
String displayedTotalPrice;
String displayedPrice;
String articleID;
String unit = "";
String articleSelected = "Artikel wählen";
class _ArticleamountState extends State<Articleamount> {
final amountController = TextEditingController();
static Color disabledColor = mainColor.withOpacity(0.5);
double price = 0.0;
double inputAmount = 0;
bool isArticleSelected = false;
bool isPriceSelected = false;
Color buttonColor = disabledColor;
String totalPrice = "0";
#override
void dispose() {
// Clean up the paremeters when the widget is disposed.
unit = "";
articlesList = {};
articleSelected = "Artikel wählen";
amountController.dispose();
super.dispose();
}
Widget articleCard(
String articleName, IconData icon, double priceForArticle) {
String tempunit = articleName.split("|")[1];
String tempID = articleName.split("&")[1].split("|")[0];
articleName = articleName.split("&")[0];
return SingleChildScrollView(
child: Container(
decoration: new BoxDecoration(
borderRadius: BorderRadius.circular(20),
),
width: 300,
height: 120,
padding: EdgeInsets.all(5),
child: MaterialButton(
child: Align(
alignment: Alignment.centerLeft,
child: Text(
articleName,
overflow: TextOverflow.fade,
style: TextStyle(fontWeight: FontWeight.bold),
)),
highlightColor: Colors.blue,
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
10,
)),
elevation: 2,
onPressed: () {
articleSelected = articleName;
articleID = tempID;
setState(() {
amountController.text = "";
totalPrice = "0";
buttonColor = disabledColor;
inputAmount = 0;
unit = tempunit;
price = priceForArticle;
isArticleSelected = true;
});
},
),
));
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: ListView(children: <Widget>[
FractionallySizedBox(
widthFactor: deviceWidth(context),
child: Center(
child: Container(
width: 600,
margin: EdgeInsets.only(top: 35),
color: Colors.transparent,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
progressBar(Nucleo.checked, "Bürger", true),
progressLine(true, context),
progressBar(
Nucleo.selected_two, "Artikel und Menge", true),
progressLine(false, context),
progressBar(Nucleo.three, "Buchung", false),
],
),
Container(
margin: EdgeInsets.only(top: 35),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Bürger".toUpperCase(),
style: TextStyle(
fontSize: 13,
color: Colors.grey,
fontWeight: FontWeight.bold),
),
new Padding(
padding: EdgeInsets.only(top: 3),
),
Text(
getCitizenInformation(),
style: TextStyle(
fontSize: 17, color: secondaryColor),
)
],
),
),
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: EdgeInsets.only(top: 30),
// width: 600,
child: Row(children: [
Column(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Artikel und Menge wählen",
style: TextStyle(
color: secondaryColor,
fontSize: 21,
fontWeight: FontWeight.bold),
),
Container(
margin: EdgeInsets.only(top: 4),
height: 5,
width: 30,
color: secondaryColor)
],
),
]),
)
],
),
Row(
children: [
Container(
margin: EdgeInsets.only(top: 40),
decoration: new BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.transparent),
width: 600,
child: Column(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
Wrap(
alignment: WrapAlignment.spaceBetween,
children: <Widget>[
for (var article in articlesList.keys)
articleCard(
article,
MdiIcons.chessQueen,
articlesList[article])
],
),
Row(
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 40),
height: 70,
width: 600,
decoration: new BoxDecoration(
borderRadius:
BorderRadius.circular(10),
color: Colors.white),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: [
Container(
width: 220,
margin:
EdgeInsets.only(left: 10),
child: TextField(
onChanged: (text) {
totalPrice = calculatePrice(
text, price);
},
keyboardType:
TextInputType.number,
controller: amountController,
decoration: InputDecoration(
labelStyle: TextStyle(
fontSize: 13),
labelText:
"$articleSelected"),
),
),
Text(
"á € $price / $unit",
style: TextStyle(
color: primaryColor,
fontSize: 20),
),
Text(
"$totalPrice€",
style: TextStyle(
color: secondaryColor,
fontSize: 20,
fontWeight:
FontWeight.bold),
),
],
),
),
],
),
Container(
margin: EdgeInsets.only(top: 30),
child: Row(
crossAxisAlignment:
CrossAxisAlignment.end,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
ButtonTheme(
minWidth: 280,
height: 50,
child: OutlineButton(
borderSide: BorderSide(
color: mainColor, width: 2),
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(
10)),
child: Text(
"Zurück",
style: TextStyle(
color: mainColor,
fontSize: 16,
),
),
onPressed: () {
Navigator.pop(context);
},
),
),
MaterialButton(
minWidth: 280,
height: 50,
color: buttonColor,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(
10)),
child: Text(
"Weiter",
style: TextStyle(
color: Colors.white,
fontSize: 16,
),
),
onPressed: () {
if (isArticleSelected == true &&
isPriceSelected == true &&
inputAmount != 0) {
Navigator.push(
context,
PageTransition(
type: PageTransitionType
.rightToLeftWithFade,
child:
Controlscreen()));
} else {
Fluttertoast.showToast(
msg:
"Eingaben bitte überprüfen",
toastLength:
Toast.LENGTH_SHORT,
gravity:
ToastGravity.BOTTOM,
timeInSecForIos: 1,
backgroundColor:
Colors.red,
textColor: Colors.white,
fontSize: 16.0);
}
}),
],
),
)
]),
),
],
),
]))))
]));
}
String calculatePrice(String inputText, double price) {
double amount;
if (inputText.isNotEmpty) {
amount = double.parse(inputText);
} else {
amount = 0;
}
double total = (amount * price);
setState(() {
totalPrice = total.toStringAsFixed(2);
isPriceSelected = true;
inputAmount = amount;
buttonColor = mainColor;
});
displayedTotalPrice = totalPrice;
displayedWeight = amount.toString();
displayedPrice = price.toString();
return totalPrice;
}
}
You can use a variable to know if a button is already pressed. Like this:
var isSelected = false;
FlatButton(
onPressed: () => { isSelected = true },
child: Text(
"Selling"
),
color: isSelected ? Theme.of(context).primaryColor : Colors.grey,
),