In my application, the user enters notes that appear as cards one below the other in order of insertion on the main page. When entering notes he selects a colored label. I would like each note entered to have the text highlighted in the color of the chosen label.
How can I do that?
Can I get the property Color of the class Label to use it on the containers of the main page cards?
This is the label.dart code
import 'package:hive/hive.dart';
#HiveType(typeId: 3)
class Label extends HiveObject {
#HiveField(0)
String name;
#HiveField(1)
int color;
Label({this.name, this.color});
}
class LabelAdapter extends TypeAdapter<Label> {
#override
final typeId = 3;
#override
Label read(BinaryReader reader) {
var numOfFields = reader.readByte();
var fields = <int, dynamic>{
for (var i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return Label(
name: fields[0] as String,
color: fields[1] as int,
);
}
#override
void write(BinaryWriter writer, Label obj) {
writer
..writeByte(2)
..writeByte(0)
..write(obj.name)
..writeByte(1)
..write(obj.color);
}
}
This is the code of the card in the main page:
Container buildTaskCard(Task personModel) {
return Container(
margin: const EdgeInsets.fromLTRB(20, 5, 20, 5),
padding: const EdgeInsets.fromLTRB(18, 10, 10, 10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: Colors.black38,
offset: Offset(0.5, 0.5),
blurRadius: 2,
),
]),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(0, 4, 0, 4.0),
child: Text(
personModel.name,
style: regularBoldTxt,
),
),
Container(
height: 1,
color: Colors.grey[300],
),
const SizedBox(height: 10),
Row(
children: [
Container(
color: Colors.red,
width: 40,
height: 50,
),
Container(
margin: const EdgeInsets.only(left: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
Text(
personModel.description,
style: regularTxt.copyWith(color: Colors.black54),
),
const SizedBox(height: 5),
Text(
personModel.statusTag ?? "",
style: regularBoldTxt,
),
],
),
)
],
),
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Icon(Icons.timer),
const SizedBox(width: 5),
Text(
DateFormat("hh:ss a").format(personModel.startTime) +
" - " +
DateFormat("hh:ss a").format(personModel.endTime),
style: regularTxt,
),
const SizedBox(width: 10),
],
),
],
),
);
}
You can pass the color to your method:
Container buildTaskCard(Task personModel, [Color color = Colors.white]) {
return Container(
margin: const EdgeInsets.fromLTRB(20, 5, 20, 5),
padding: const EdgeInsets.fromLTRB(18, 10, 10, 10),
decoration: BoxDecoration(
color: color, //I believe you want to change this color?
borderRadius: BorderRadius.circular(10),
....
);
Then whenever you call this method you use the int of your label class to create your color and pass it
late final Widget container;
final Task task = ... //your taks;
final Label? label = box.get('myLabels') as Label?; // I dont't know where you call your box or what is its name
if (label != null) {
final Color color = Color(label.color);
container = buildTaskCard(mytask, color);
} else {
container = buildTaskCard(mytask);
}
....
And construct your widget with it
Related
hey why is my itemcount not working i have 6 rows in my database but when i run the code it show me only one row and the other rows not showing it
this is my code:
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
class my_ads extends StatefulWidget {
const my_ads({Key? key}) : super(key: key);
#override
State<my_ads> createState() => _my_adsState();
}
List list = [];
int select_item = 0;
class _my_adsState extends State<my_ads> {
#override
Future ReadData() async {
var url = "https://***.***.***.**/getData.php";
var res = await http.get(Uri.parse(url));
if (res.statusCode == 200) {
var red = jsonDecode(res.body);
setState(() {
list.addAll(red);
});
print(list);
}
}
#override
void initState() {
super.initState();
GetData();
}
GetData() async {
await ReadData();
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: ListView.builder(
itemCount: list.length,
itemBuilder: ((cts, i) {
return Container(
height: 800,
child: ListView(
children: [
Container(
margin: EdgeInsets.only(left: 70, right: 60),
height: 54.0,
width: 224.0,
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: Color(0xffF4AC47), width: 5),
color: Color(0xff42A9D2),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(40),
bottomRight: Radius.circular(40))),
child: new Center(
child: new Text(
"MyAds",
style: TextStyle(
fontSize: 25,
color: Color(0xff072A52),
fontFamily: 'Cairo'),
textAlign: TextAlign.center,
),
//end logo
)),
),
///start Section
Container(
margin: EdgeInsets.only(left: 10, right: 10, top: 10),
height: 180.0,
width: 430.0,
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: Color(0xff42A9D2), width: 5),
borderRadius: BorderRadius.circular(8)),
child: new Container(
child: Row(
children: [
Expanded(
child: Image(
image: AssetImage("assets/book.jpg"),
)),
Container(
margin: EdgeInsets.only(
left: 110, top: 30, right: 13),
child: Column(
children: [
Text(
"test",
style: TextStyle(
fontSize: 20, color: Colors.black87),
),
SizedBox(
height: 20,
),
Row(
children: [
Text("test2"),
Icon(Icons.perm_identity_rounded)
],
),
SizedBox(
height: 5,
),
Row(
children: [
Text("}"),
Column(
children: [Icon(Icons.store)],
)
],
),
],
),
)
],
)
//end logo
)),
),
],
),
);
})));
}
}
i tried to change ListView to ListTile but the design will be detroyed becuse i need to make the same design to other pages but my problem is with itemcount its not making any changes ! please if you have any ideas with my problem give me ansewrs
I have problem, when I run the code it works but when I out from the page and go back it show x2 for the rows its looping without any loop I make in my database 7 rows when I out and return to the same page it shows 14 rows but I have onlu 7 rows.
This is my code:
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
class my_ads extends StatefulWidget {
const my_ads({Key? key}) : super(key: key);
#override
State<my_ads> createState() => _my_adsState();
}
List list = [];
int select_item = 0;
class _my_adsState extends State<my_ads> {
#override
Future MyAds() async {
final response =
await http.get(Uri.parse('https://***.***.***.**/getData.php'));
if (response.statusCode == 200) {
var red = jsonDecode(response.body);
setState(() {
list.addAll(red);
});
} else {
// If the server did not return a 200 OK response,
// then throw an exception.
throw Exception('Failed to load Ads');
}
}
#override
void initState() {
super.initState();
GetData();
}
GetData() async {
await MyAds();
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Container(
margin: const EdgeInsets.only(left: 70, right: 60, top: 50),
height: 54.0,
width: 224.0,
child: Container(
decoration: BoxDecoration(
border:
Border.all(color: const Color(0xffF4AC47), width: 5),
color: const Color(0xff42A9D2),
borderRadius: const BorderRadius.only(
bottomLeft: Radius.circular(40),
bottomRight: Radius.circular(40))),
child: const Center(
child: Text(
"MyAds",
style: TextStyle(
fontSize: 25,
color: Color(0xff072A52),
fontFamily: 'Cairo'),
textAlign: TextAlign.center,
),
//end logo
)),
),
const SizedBox(
height: 35,
),
Expanded(
child: ListView.builder(
itemCount: list.length,
itemBuilder: ((cts, i) {
return Column(
children: [
Container(
margin: const EdgeInsets.symmetric(horizontal: 10),
height: 180.0,
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: const Color(0xff42A9D2), width: 5),
borderRadius: BorderRadius.circular(8)),
child: Row(
children: [
const Expanded(
flex: 3,
child: Image(
image: AssetImage("assets/book.jpg"),
),
),
Expanded(
flex: 6,
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"${list[i]["book_name"]}",
style: TextStyle(
fontSize: 20, color: Colors.black87),
),
const SizedBox(height: 12),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text("${list[i]["collage"]}"),
const Icon(Icons.perm_identity_rounded)
],
),
const SizedBox(height: 12),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text("${list[i]["loc"]}"),
const Icon(Icons.store)
],
),
],
),
)
],
),
),
),
const SizedBox(height: 16),
],
);
}),
),
),
],
),
);
}
}
I tried to add this method to my PHP code $mysqli_connect-> close();
But its not working
This is my PHP code:
<?php
include("config.php");
$sql = "SELECT book_name,loc,com,spe,collage FROM ads";
$res = $connect->query($sql);
while($row = $res -> fetch_assoc()) {
$data[]=$row;
}
echo json_encode($data);
$mysqli_connect-> close();
?>
You declared list outside. It will maintain its state even when you change screens.
Either you declared it inside the state widget or replace :
list.addAll(red);
by :
list = red;
I'm still new in flutter, does anyone know how to make the search in the tab card like picture below:
I try to figure it out how to solve this problem but still be like this:
Here is My code that I try to solve, I'm using the custom card, the custom dialog :
class TabbedCard extends StatefulWidget {
final List<Tab> tabs;
final List<Widget> children;
final bool showDeleteBtn;
final bool showPrimaryBtn;
const TabbedCard(
{Key? key,
required this.tabs,
required this.children,
this.showDeleteBtn = false,
this.showPrimaryBtn = true})
: super(key: key);
#override
State<TabbedCard> createState() => _TabbedCardState();
}
class _TabbedCardState extends State<TabbedCard> with TickerProviderStateMixin {
#override
Widget build(BuildContext context) {
double _scrHeight = MediaQuery.of(context).size.height - 150;
// String searchText = "";
TextEditingController textController = new TextEditingController();
TabController _controller =
TabController(length: widget.tabs.length, vsync: this);
TabBar _tabBar = new TabBar(
isScrollable: true,
labelColor: kPrimaryColor,
unselectedLabelColor: kTextGray,
controller: _controller,
tabs: widget.tabs,
);
return Container(
constraints: BoxConstraints(minHeight: _scrHeight),
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.symmetric(
vertical: 1,
horizontal: 1,
),
decoration: BoxDecoration(
border: Border.all(
color: Colors.white,
),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.white.withOpacity(0.5),
spreadRadius: -4,
blurRadius: 35,
offset: const Offset(0, 9), // changes position of shadow
),
],
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Align(
alignment: Alignment.topLeft,
child: Row(
children: [
AnimSearchBar(
width: 400,
textController: textController,
onSuffixTap: (value) {
setState(() {});
},
),
const SizedBox(width: 10),
_tabBar,
const SizedBox(width: 10),
],
)),
const SizedBox(height: 10),
Container(
height: 440,
child: TabBarView(
controller: _controller,
children: widget.children,
),
),
],
),
),
const SizedBox(height: 10),
],
),
),
);
}
}
Really appreciate if anyone can help me with this problem ^^
You can try this:
first create bool showSearchView = false, then create two widget like this:
_tabView() {
return Row(
children: [
Container(
color: Colors.red,
width: 100,
height: 40,
),
Container(
margin: EdgeInsets.symmetric(horizontal: 16),
color: Colors.red,
width: 100,
height: 40,
),
Container(
color: Colors.red,
width: 100,
height: 40,
),
],
);
}
and
_searchView() {
return TextField();
}
then, use it like this:
Row(
children: [
InkWell(
onTap: () {
setState(() {
showSearchView = !showSearchView;
});
},
child: Icon(showSearchView ? Icons.close : Icons.search),
),
Expanded(
child: showSearchView ? _searchView() : _tabView(),
),
],
),
So, I'm pretty new on Flutter (just about a week) and dart but I hope this Question is not toooooo stupid:
I'm trying to create an App for an existing Website (a forum). I dont want to use the flutter WebView, because I want to create an comepletly new Interface (The Website is not optimized for mobile View, that's why I'm builing this App).
The (german) Forum:
https://www.porsche-914.com/forum
I want to fetch the single forum topics as well as the posts itself including username, title and date and then map the text to a custom widget to display it. The Widget Part is no problem, it's already done but I cant figure out how to fetch that data from the website and how to store it.
I don't know, hope you can help me...
Thanks a lot for the taken time.
How the mapping should work:
fetched[index].title, fetched[index].text
Center(
child: NeumorphismPost(
title: fetched[index].title,
titleColor: Theme.of(context).cardColor,
textColor: Theme.of(context).cardColor,
text: fetched[index].text,
width: 370,
onTap: () {
_popupPage(context,
title: fetched[index].title,
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Text(
fetched[index].text,
style: TextStyle(
color: Theme.of(context).cardColor,
fontSize: 18),
),
),
);
},
),
),
This is my custom Widget:
import 'package:flutter/material.dart';
class NeumorphismPost extends StatefulWidget {
final double width;
final double height;
final double borderRadius;
final String title;
final String text;
final Color titleColor;
final Color textColor;
final double titleSize;
final double textSize;
final Function onTap;
NeumorphismPost({
this.width = 185,
this.height = 185,
this.title = "Title",
this.text = "",
this.borderRadius = 20,
this.titleColor = const Color(0xFF424242),
this.textColor = const Color(0xFF424242),
this.titleSize = 22,
this.textSize = 18,
required this.onTap,
});
#override
State<NeumorphismPost> createState() => _NeumorphismPostState();
}
class _NeumorphismPostState extends State<NeumorphismPost> {
#override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Wrap(
direction: Axis.vertical,
children: [
SingleChildScrollView(
child: SizedBox(
height: widget.height,
width: widget.width,
child: GestureDetector(
onTap: () {},
child: Scaffold(
backgroundColor: Colors.transparent,
body: SizedBox(
height: widget.height,
width: widget.width,
child: Center(
child: Container(
height: widget.height,
width: widget.width,
decoration: BoxDecoration(
color: Theme.of(context).backgroundColor,
borderRadius:
BorderRadius.circular(widget.borderRadius),
boxShadow: [
BoxShadow(
color: Theme.of(context).hintColor,
offset: const Offset(5, 5),
blurRadius: 15,
spreadRadius: 1,
),
BoxShadow(
color: Theme.of(context).backgroundColor,
offset: Offset(-5, -5),
blurRadius: 15,
spreadRadius: 1,
)
],
),
child: Wrap(
direction: Axis.horizontal,
children: [
SingleChildScrollView(
child: Center(
child: Column(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: <Widget>[
Wrap(
direction: Axis.horizontal,
children: [
SizedBox(
height: widget.height / 3,
child: Wrap(
children: [
Column(
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets
.symmetric(
horizontal: 15,
vertical: 15),
child: Text(
widget.title,
textAlign:
TextAlign.center,
overflow:
TextOverflow.fade,
style: TextStyle(
fontSize:
widget.titleSize,
fontWeight:
FontWeight.bold,
color:
widget.titleColor,
),
),
),
],
),
],
),
),
],
),
Wrap(
direction: Axis.horizontal,
children: [
GestureDetector(
onTap: () {
widget.onTap();
},
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 5),
child: SizedBox(
height: widget.height / 1.38,
child: Padding(
padding:
const EdgeInsets.symmetric(
horizontal: 15,
vertical: 15),
child: Text(
widget.text,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: widget.textSize,
fontWeight:
FontWeight.normal,
color: widget.textColor,
),
),
),
),
),
),
],
),
],
),
),
),
],
),
),
),
),
),
),
),
),
],
),
);
}
}
From my point of view, you want to create a scraper. I checked the target website (https://www.porsche-914.com/forum), it can be scraped without any special technique (they don't have many Ajax calls (you may test by using Postman)). So it is a possible task. My suggestion flow is:
Load the raw HTML using any technique (http, dio, inappwebview ...)
Parse it using BeautifulSoup (https://pub.dev/packages/beautiful_soup_dart) (or any parser; it is just my favorite parser.)
Map it to your existing model.
Here is some example code. Hope it helps:
import 'package:http/http.dart' as http;
import 'package:beautiful_soup_dart/beautiful_soup.dart';
class TestParse {
excuteSample() async {
var url = Uri.parse('https://www.porsche-914.com/forum');
var response = await http.get(url);
BeautifulSoup bs = BeautifulSoup(response.body);
final allHeaderName = bs.findAll('td', attrs: {'class': 'oben'});
allHeaderName.forEach((element) {
print('the header: ${element.text}');
});
}
}
Here is the result:
The final result you need is a long story and long code. Hope this will give you a starting point.
UPDATE: I added the full demo code, using your requested code:
import 'package:beautiful_soup_dart/beautiful_soup.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
void main() => runApp(const MaterialApp(home: MyApp()));
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
#override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final testparse = TestParse();
List<String> yourModelPleaseReplaceThis = [];
#override
void initState() {
super.initState();
excuteRequestAndParse();
}
excuteRequestAndParse() async {
final result =
await testparse.excuteSample(); //[1] i guess you missing this await
setState(() {
yourModelPleaseReplaceThis = result;
});
}
#override
Widget build(BuildContext context) {
return ListView.builder(
itemBuilder: (context, index) {
return Center(
child: NeumorphismPost(
title: yourModelPleaseReplaceThis[index],
titleColor: Theme.of(context).cardColor,
textColor: Theme.of(context).cardColor,
text: yourModelPleaseReplaceThis[index],
width: 370,
onTap: () {
//THIS CODE BELOW IS YOUR CODE....
},
),
);
},
itemCount: yourModelPleaseReplaceThis.length,
);
}
}
// BELOW IS TESTING CODE....
class TestParse {
Future<List<String>> excuteSample() async {
var url = Uri.parse('https://www.porsche-914.com/forum');
var response = await http.get(url);
BeautifulSoup bs = BeautifulSoup(response.body);
final allHeaderName = bs.findAll('td', attrs: {'class': 'oben'});
allHeaderName.forEach((element) {
print('the header: ${element.text}');
});
return Future.value(allHeaderName.map((e) => e.text).toList());
}
}
class NeumorphismPost extends StatefulWidget {
final double width;
final double height;
final double borderRadius;
final String title;
final String text;
final Color titleColor;
final Color textColor;
final double titleSize;
final double textSize;
final Function onTap;
NeumorphismPost({
this.width = 185,
this.height = 185,
this.title = "Title",
this.text = "",
this.borderRadius = 20,
this.titleColor = const Color(0xFF424242),
this.textColor = const Color(0xFF424242),
this.titleSize = 22,
this.textSize = 18,
required this.onTap,
});
#override
State<NeumorphismPost> createState() => _NeumorphismPostState();
}
class _NeumorphismPostState extends State<NeumorphismPost> {
#override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Wrap(
direction: Axis.vertical,
children: [
SingleChildScrollView(
child: SizedBox(
height: widget.height,
width: widget.width,
child: GestureDetector(
onTap: () {},
child: Scaffold(
backgroundColor: Colors.transparent,
body: SizedBox(
height: widget.height,
width: widget.width,
child: Center(
child: Container(
height: widget.height,
width: widget.width,
decoration: BoxDecoration(
color: Theme.of(context).backgroundColor,
borderRadius:
BorderRadius.circular(widget.borderRadius),
boxShadow: [
BoxShadow(
color: Theme.of(context).hintColor,
offset: const Offset(5, 5),
blurRadius: 15,
spreadRadius: 1,
),
BoxShadow(
color: Theme.of(context).backgroundColor,
offset: Offset(-5, -5),
blurRadius: 15,
spreadRadius: 1,
)
],
),
child: Wrap(
direction: Axis.horizontal,
children: [
SingleChildScrollView(
child: Center(
child: Column(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: <Widget>[
Wrap(
direction: Axis.horizontal,
children: [
SizedBox(
height: widget.height / 3,
child: Wrap(
children: [
Column(
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets
.symmetric(
horizontal: 15,
vertical: 15),
child: Text(
widget.title,
textAlign:
TextAlign.center,
overflow:
TextOverflow.fade,
style: TextStyle(
fontSize:
widget.titleSize,
fontWeight:
FontWeight.bold,
color:
widget.titleColor,
),
),
),
],
),
],
),
),
],
),
Wrap(
direction: Axis.horizontal,
children: [
GestureDetector(
onTap: () {
widget.onTap();
},
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 5),
child: SizedBox(
height: widget.height / 1.38,
child: Padding(
padding:
const EdgeInsets.symmetric(
horizontal: 15,
vertical: 15),
child: Text(
widget.text,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: widget.textSize,
fontWeight:
FontWeight.normal,
color: widget.textColor,
),
),
),
),
),
),
],
),
],
),
),
),
],
),
),
),
),
),
),
),
),
],
),
);
}
}
This is the result:
Please note:
This list I created is for sample, so it is just a list of Strings. You should create a complete Model.
I have some Radios and i want to take some different String based on which Radio is selected.
These Radios are located in another file, and there are several files which i want to take data and bring to my main file and than to save these data into my cloud firebase.
I created another file to store all these Informations but i cant save these data into this class. Can u show me some ways how can i do that?
//this is my informations class
class Informations {
String nom;
String lieu;
String type;
String typDePlonge;
String topographie;
String temperatureEau;
String courant;
String visibilite;
String niveauRequis;
String autonomie;
String quandPlonger;
String requin;
String mammifere;
String reptile;
String crustace;
String raie;
String limace;
String cephalopode;
String corail;
String poissonPelagique;
String poissonDeRecif;
String poissonDeFond;
String vmAutres;
String niveauAcceptes;
String activitesProposes;
String photo;
Informations(
{this.type,
this.nom,
this.photo,
this.activitesProposes,
this.autonomie,
this.cephalopode,
this.corail,
this.courant,
this.crustace,
this.lieu,
this.limace,
this.mammifere,
this.niveauAcceptes,
this.niveauRequis,
this.poissonDeFond,
this.poissonDeRecif,
this.poissonPelagique,
this.quandPlonger,
this.raie,
this.reptile,
this.requin,
this.temperatureEau,
this.topographie,
this.typDePlonge,
this.visibilite,
this.vmAutres});
}
//this is where i have my data.
//For each radio selected i want to take that string which is near the radio,
//the string which is shown at the text widget.
class ActivitesProposes extends StatefulWidget {
const ActivitesProposes({Key key}) : super(key: key);
#override
_ActivitesProposesState createState() => _ActivitesProposesState();
}
class _ActivitesProposesState extends State<ActivitesProposes> {
bool isStrechedActivities = false;
int groupValueActivities = 0;
void handleGroupValueActivities(int value) {
setState(() {
groupValueActivities = value;
});
}
#override
Widget build(BuildContext context) {
return new Padding(
padding: EdgeInsets.fromLTRB(20, 10, 20, 0),
child: Container(
// height: double.infinity,
width: double.infinity,
child: Padding(
padding: const EdgeInsets.all(2.0),
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Row(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Container(
decoration: BoxDecoration(
border: GradientBorder.uniform(
width: 3.0,
gradient: LinearGradient(colors: <Color>[
Color(0xff59a5da),
Color(0xff60af6c)
], stops: [
0.3,
0.5
])),
borderRadius: BorderRadius.circular(30.0),
),
child: Column(
children: [
Container(
height: 45,
width: double.infinity,
padding: EdgeInsets.only(right: 10),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: <Color>[
Color(0xff59a5da),
Color(0xff60af6c),
]),
borderRadius: BorderRadius.all(
Radius.circular(25))),
constraints: BoxConstraints(
minHeight: 45,
minWidth: double.infinity,
),
alignment: Alignment.center,
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Padding(
padding:
const EdgeInsets.symmetric(
horizontal: 10,
vertical: 10),
child: Text(
'Activités proposées',
style: new TextStyle(
fontSize: 20,
color: Colors.white,
decorationThickness: 3.0,
fontWeight: FontWeight.w900,
),
),
),
),
Padding(
padding: const EdgeInsets.all(0.0),
child: GestureDetector(
onTap: () {
setState(() {
isStrechedActivities =
!isStrechedActivities;
});
},
child: Icon(
isStrechedActivities
? Icons.keyboard_arrow_up
: Icons.keyboard_arrow_down,
color: Colors.white,
size: 40,
),
),
),
],
),
),
ExpandedSectionThreeRows(
expand: isStrechedActivities,
height: 100,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 18.0),
child: Container(
color: Colors.white70,
child: ListView(
padding: EdgeInsets.all(0),
shrinkWrap: true,
children: [
//controller: scrollController2,
Row(
children: [
Radio(
value: 0,
groupValue:
groupValueActivities,
onChanged:
handleGroupValueActivities),
new Text('cours plongée',
style: new TextStyle(
color:
groupValueActivities ==
0
? Colors.blue
.shade900
: Colors.black,
)),
],
),
Row(
children: [
Radio(
value: 1,
groupValue:
groupValueActivities,
onChanged:
handleGroupValueActivities),
new Text('sortie bateau',
style: new TextStyle(
color:
groupValueActivities ==
1
? Colors.blue
.shade900
: Colors
.black)),
],
),
Row(
children: [
Radio(
value: 2,
groupValue:
groupValueActivities,
onChanged:
handleGroupValueActivities),
new Text(
'location équipement',
style: new TextStyle(
color:
groupValueActivities ==
2
? Colors.blue
.shade900
: Colors.black,
)),
],
),
],
),
),
),
),
],
),
))
],
),
],
),
)),
);
}
}
//The button where im gonna register these data is on another file.
i fixed this really easy, i dont know why i wrote this question here anyway XD.
here is the code:
final informations = Informations();//added a reference for my informations class
// at the function of my radio i added this code and based on what radio
// is selected i add a diff text to my Informations class variable
void handleGroupValueActivities(int value) {
setState(() {
groupValueActivities = value;
if (groupValueActivities == 0){
informations.activitesProposes = 'cours plongee';
}else if(groupValueActivities == 1){
informations.activitesProposes = 'sortie bateau';
}else if(groupValueActivities == 2){
informations.activitesProposes = 'location equipment';
}else {
infromations.activitesProposes = null;
}// and if none of them is selected i return null.
print(informations.activitesProposes);
});
}