Skip to content

Commit

Permalink
Changed from stateless to statefull
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivaskuu committed Nov 3, 2017
1 parent fc71161 commit beeb83d
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 98 deletions.
4 changes: 2 additions & 2 deletions lib/lista_citta.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class ListaCitta
{
List<Citta> citta =
static List<Citta> listaCitta =
[
new Citta
(
Expand Down Expand Up @@ -30,7 +30,7 @@ class ListaCitta
new Luogo
(
nome: "Tempio Kiyomizu",
descrizione: "Tempio molto bello",
descrizione: "Questo vecchio tempio è stato creato da molti shaolin che volevano avere un luogo tranquillo dove allenarsi mentre fuori c'era la guerra.",
img: "res/citta/kyoto-0.jpg"
),
new Luogo
Expand Down
166 changes: 85 additions & 81 deletions lib/screen_citta.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import 'package:flutter/material.dart';
import 'lista_citta.dart';

class ScreenCitta extends StatelessWidget
class ScreenCitta extends StatefulWidget
{
Citta _citta;
ScreenCitta(this._citta);

@override
State createState() => new ScreenCittaState();
}

class ScreenCittaState extends State<ScreenCitta>
{
Widget build(BuildContext context)
{
Expand All @@ -9,22 +19,17 @@ class ScreenCitta extends StatelessWidget
appBar: new AppBar
(
backgroundColor: Colors.white,
title: new Text("Kyoto (4/4)"),
title: new Text("${widget._citta.nome}"/* (4/${widget._citta.luoghi.length})"*/),
actions: <Widget>
[
new IconButton(icon: new Icon(Icons.search), onPressed: () => null)
],
),
body: new ListView
body: new ListView.builder
(
itemBuilder: (_, int i) => new TileLuogo(widget._citta.luoghi[i]),
itemCount: widget._citta.luoghi.length,
scrollDirection: Axis.vertical,
children: <Widget>
[
new TileLuogo("Tempio Kiyomizu", "res/citta/kyoto-0.jpg"),
new TileLuogo("Fushimi Inari", "res/citta/kyoto-1.jpg"),
new TileLuogo("Arashyana", "res/citta/kyoto-2.jpg"),
new TileLuogo("Tempio Nanzen-ji", "res/citta/kyoto-3.jpg"),
],
),
floatingActionButton: new FloatingActionButton
(
Expand All @@ -34,96 +39,95 @@ class ScreenCitta extends StatelessWidget
),
);
}
}

class TileLuogo extends StatefulWidget
{
final Luogo _luogo;
TileLuogo(this._luogo);

bool selected = true;

@override
State createState() => new TileLuogoState();
}

Widget pillButton()
class TileLuogoState extends State<TileLuogo>
{
Widget build(BuildContext context)
{
return new Container
return new GestureDetector
(
margin: new EdgeInsets.symmetric(horizontal: 16.0, vertical: 4.0),
onTap: () => setState(() => widget.selected = !widget.selected),
onLongPress: () => _longPress(context),
child: new Material
(
elevation: 8.0,
borderRadius: new BorderRadius.circular(32.0),
child: new InkWell
child: new Container
(
onTap: () => null,
child: new Container
margin: new EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
decoration: new BoxDecoration
(
decoration: new BoxDecoration
borderRadius: new BorderRadius.all(new Radius.circular(20.0)),
image: new DecorationImage
(
borderRadius: new BorderRadius.circular(32.0),
gradient: new LinearGradient
(
colors: [Colors.amberAccent, Colors.greenAccent],
),
image: new AssetImage(widget._luogo.img),
fit: BoxFit.cover,
colorFilter: new ColorFilter.mode(Colors.black45, BlendMode.luminosity)
)
),
child: new SizedBox.fromSize
(
size: new Size.fromHeight(180.0),
child: new Stack
(
children: <Widget>
[
new Align
(
alignment: FractionalOffset.topRight,
child: new Container
(
margin: new EdgeInsets.all(8.0),
child: new Checkbox
(
value: widget.selected,
onChanged: (bool newValue) => setState(() => widget.selected = newValue),
)
)
),
new Align
(
alignment: FractionalOffset.bottomLeft,
child: new Container
(
margin: new EdgeInsets.all(16.0),
child: new Text(widget._luogo.nome, style: new TextStyle(color: Colors.white, fontSize: 24.0, fontWeight: FontWeight.bold)),
)
),
],
),
child: new Text("VAI", textAlign: TextAlign.center, style: new TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
padding: new EdgeInsets.symmetric(horizontal: 80.0, vertical: 20.0),
),
)
)
);
}
}

class TileLuogo extends StatelessWidget
{
String _nomeLuogo;
String _img;
TileLuogo(this._nomeLuogo, this._img);

bool selected = true;

Widget build(BuildContext context)
void _longPress(BuildContext context)
{
return new Material
showDialog
(
elevation: 8.0,
child: new Container
context: context,
child: new SimpleDialog
(
margin: new EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
decoration: new BoxDecoration
(
borderRadius: new BorderRadius.all(new Radius.circular(20.0)),
image: new DecorationImage
(
image: new AssetImage(_img),
fit: BoxFit.cover,
colorFilter: new ColorFilter.mode(Colors.black45, BlendMode.luminosity)
)
),
child: new SizedBox.fromSize
(
size: new Size.fromHeight(180.0),
child: new Stack
(
children: <Widget>
[
new Align
(
alignment: FractionalOffset.topRight,
child: new Container
(
margin: new EdgeInsets.all(8.0),
child: new Checkbox
(
value: selected,
onChanged: (bool newValue) => selected = newValue,
)
)
),
new Align
(
alignment: FractionalOffset.bottomLeft,
child: new Container
(
margin: new EdgeInsets.all(16.0),
child: new Text(_nomeLuogo, style: new TextStyle(color: Colors.white, fontSize: 24.0, fontWeight: FontWeight.bold)),
)
),
],
),
),
contentPadding: new EdgeInsets.all(0.0),
children: <Widget>
[
new Image.asset(widget._luogo.img),
new Text(widget._luogo.nome, style: Theme.of(context).textTheme.title),
new Text(widget._luogo.descrizione),
//new Text(_luogo.posizione)
],
)
);
}
Expand Down
24 changes: 9 additions & 15 deletions lib/screen_lista_citta.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'lista_citta.dart';
import 'screen_citta.dart';

class ListaCittaScreen extends StatelessWidget
Expand All @@ -7,26 +8,19 @@ class ListaCittaScreen extends StatelessWidget
{
return new Scaffold
(
body: new PageView
body: new PageView.builder
(
children: <Widget>
[
new CopertinaCitta("New York", "res/citta/new-york.jpg"),
new CopertinaCitta("Paris", "res/citta/paris.jpg"),
new CopertinaCitta("Tokyo", "res/citta/tokyo.jpg"),
new CopertinaCitta("Kyoto", "res/citta/kyoto.jpg"),
new CopertinaCitta("St Petersburg", "res/citta/st-petersburg.jpg"),
],
itemBuilder: (_, int i) => new CopertinaCitta(ListaCitta.listaCitta[i]),
itemCount: ListaCitta.listaCitta.length,
)
);
}
}

class CopertinaCitta extends StatelessWidget
{
String _nomeCitta;
String _img;
CopertinaCitta(this._nomeCitta, this._img);
Citta citta;
CopertinaCitta(this.citta);

Widget build(BuildContext context)
{
Expand All @@ -36,7 +30,7 @@ class CopertinaCitta extends StatelessWidget
(
image: new DecorationImage
(
image: new AssetImage(_img),
image: new AssetImage(citta.img),
fit: BoxFit.cover,
colorFilter: new ColorFilter.mode(Colors.black45, BlendMode.luminosity)
)
Expand All @@ -51,7 +45,7 @@ class CopertinaCitta extends StatelessWidget
child: new Container
(
margin: new EdgeInsets.only(top: 32.0, left: 24.0, right: 24.0),
child: new Text(_nomeCitta.toUpperCase(), style: new TextStyle(color: Colors.white, fontSize: 90.0, fontWeight: FontWeight.w700)),
child: new Text(citta.nome.toUpperCase(), style: new TextStyle(color: Colors.white, fontSize: 90.0, fontWeight: FontWeight.w700)),
)
),
new Align
Expand All @@ -64,7 +58,7 @@ class CopertinaCitta extends StatelessWidget
(
backgroundColor: Colors.white,
child: new Icon(Icons.keyboard_arrow_up, color: Colors.black),
onPressed: () => Navigator.of(context).push(new MaterialPageRoute(builder: (_) => new ScreenCitta()))
onPressed: () => Navigator.of(context).push(new MaterialPageRoute(builder: (_) => new ScreenCitta(citta)))
)
)
),
Expand Down

0 comments on commit beeb83d

Please sign in to comment.