-
-
Save mmanflori/ea87889bdac4c878809b8d702174629d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
List<String> namen = ["Frida Müller","Helene Kowaschek","Trude Mustgard"]; | |
class _MeinInherited extends InheritedWidget{ | |
_MeinInherited({ | |
Key key, | |
@required Widget child, | |
@required this.data, | |
}):super(key:key,child:child); | |
final MeinInheritedWidgetState data; // hier befinden sich unsere Daten, dynamische Daten | |
@override | |
bool updateShouldNotify(_MeinInherited oldWidget){ //eine eingebaute Methode, die überprüft ob sich am "State" etwas geändert hat | |
return true; | |
} | |
} | |
class MeinInheritedWidget extends StatefulWidget{ | |
MeinInheritedWidget({ | |
Key key, | |
this.child, | |
}):super(key:key); | |
final Widget child; | |
@override | |
MeinInheritedWidgetState createState() => new MeinInheritedWidgetState(); | |
static MeinInheritedWidgetState of(BuildContext context){ | |
return (context.inheritFromWidgetOfExactType(_MeinInherited) as _MeinInherited).data; | |
} | |
} | |
class MeinInheritedWidgetState extends State<MeinInheritedWidget>{ //hier passiert alles spannende | |
bool gedruckt=true; | |
int zaehler=0; | |
int zaehler1=0; | |
dynamic deco=boxDeco; | |
int buttonnr=0; | |
int get aufzahlen{ | |
if(zaehler>=2){zaehler=-1;} | |
zaehler = zaehler+1; | |
return zaehler; | |
} | |
int get aufzahlen1{ | |
if(zaehler1>=2){zaehler1=-1;} | |
zaehler1 = zaehler1+1; | |
return zaehler; | |
} | |
void toggleGedruckt(bool gedruckt){ | |
setState(() { | |
if (gedruckt) { | |
deco = boxDeco1; | |
gedruckt=false; | |
print(gedruckt); | |
} else { | |
deco = boxDeco; | |
gedruckt=true; | |
print(gedruckt); | |
} | |
}); | |
} | |
@override | |
Widget build(BuildContext context){ | |
return new _MeinInherited( | |
data: this, | |
child: widget.child, | |
); | |
} | |
} | |
void main()=>runApp(MeinProg()); | |
class MeinProg extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: MeinAppBaum(), | |
); | |
} | |
} | |
class MeinAppBaum extends StatefulWidget { | |
@override | |
_MeinAppBaumState createState() => _MeinAppBaumState(); | |
} | |
class _MeinAppBaumState extends State<MeinAppBaum> { | |
@override | |
Widget build(BuildContext context) { | |
return new MeinInheritedWidget( | |
child: new Scaffold( | |
appBar: new AppBar( | |
title:new Text( | |
"Phone Book" | |
), | |
), | |
body: new Column( | |
children: <Widget>[ | |
abStand, | |
Row( | |
crossAxisAlignment: CrossAxisAlignment.center, | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
abStand, | |
MeinButton1(), | |
PbookEintrag1(), | |
], | |
), | |
Row( | |
crossAxisAlignment: CrossAxisAlignment.center, | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
abStand, | |
MeinButton2(), | |
PbookEintrag2(), | |
], | |
) | |
], | |
), | |
), | |
); | |
} | |
} | |
dynamic boxDeco = BoxDecoration( | |
border: Border.all( | |
color:Colors.black, | |
width: 2.0, | |
style: BorderStyle.none, | |
), | |
color: Colors.grey[50], | |
borderRadius: BorderRadius.all( | |
Radius.circular( | |
10.0 | |
) | |
), | |
boxShadow: [BoxShadow( | |
color: Colors.grey, | |
offset: Offset(3.0, 3.0), | |
blurRadius: 5.0, | |
)], | |
); | |
dynamic boxDeco1 = BoxDecoration( | |
border: Border.all( | |
color:Colors.black, | |
width: 2.0, | |
style: BorderStyle.none, | |
), | |
color: Colors.grey[50], | |
borderRadius: BorderRadius.all( | |
Radius.circular( | |
10.0 | |
) | |
), | |
boxShadow: [BoxShadow( | |
color: Colors.grey, | |
offset: Offset(1.0, 1.0), | |
blurRadius: 1.0, | |
)], | |
); | |
Widget abStand = new SizedBox(width: 24.0,height: 48.0,); | |
Widget abStandb = new SizedBox(width: 48.0,height: 24.0,); | |
class MeinButton1 extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
final MeinInheritedWidgetState state = MeinInheritedWidget.of(context); | |
return Container( | |
decoration:state.deco, | |
child: IconButton( | |
iconSize: 32, | |
splashColor: Colors.blue[50], | |
icon: Icon( | |
Icons.person, | |
), | |
onPressed: () { | |
state.toggleGedruckt(state.gedruckt); | |
state.aufzahlen; | |
state.buttonnr=1; | |
}, | |
), | |
); | |
} | |
} | |
class MeinButton2 extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
final MeinInheritedWidgetState state = MeinInheritedWidget.of(context); | |
return Container( | |
decoration:state.deco, | |
child: IconButton( | |
iconSize: 32, | |
splashColor: Colors.blue[50], | |
icon: Icon( | |
Icons.person, | |
), | |
onPressed: () { | |
state.toggleGedruckt(state.gedruckt); | |
state.aufzahlen1; | |
state.buttonnr=2; | |
}, | |
), | |
); | |
} | |
} | |
class PbookEintrag1 extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
final MeinInheritedWidgetState state = MeinInheritedWidget.of(context); | |
return Container( | |
margin: EdgeInsets.all(5.0), | |
alignment: Alignment.centerLeft, | |
constraints: BoxConstraints.expand( | |
width: 300.0, | |
height: 48.0, | |
), | |
decoration: state.deco, | |
child:Text( | |
"${namen[state.zaehler]}", | |
style: TextStyle( | |
fontSize: 24.0, | |
), | |
), | |
); | |
} | |
} | |
class PbookEintrag2 extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
final MeinInheritedWidgetState state = MeinInheritedWidget.of(context); | |
return Container( | |
margin: EdgeInsets.all(5.0), | |
alignment: Alignment.centerLeft, | |
constraints: BoxConstraints.expand( | |
width: 300.0, | |
height: 48.0, | |
), | |
decoration: state.deco, | |
child:Text( | |
"${namen[state.zaehler1]}", | |
style: TextStyle( | |
fontSize: 24.0, | |
), | |
), | |
); | |
} | |
} | |
class PbookEintrag3 extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
final MeinInheritedWidgetState state = MeinInheritedWidget.of(context); | |
return Container( | |
margin: EdgeInsets.all(5.0), | |
alignment: Alignment.centerLeft, | |
constraints: BoxConstraints.expand( | |
width: 300.0, | |
height: 48.0, | |
), | |
decoration: state.deco, | |
child:Text( | |
"${namen[state.zaehler]}", | |
style: TextStyle( | |
fontSize: 24.0, | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment