This file contains hidden or 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
extension View { | |
func toAnyView() -> AnyView { | |
return AnyView(self) | |
} | |
} | |
enum Route { | |
case detail(String) | |
case aboutUs | |
case addCountry |
This file contains hidden or 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
struct ContentView: View { | |
let countries = ["Pakistan", "United States", "Canada", "Iceland", "Thailand", "England", "Australia"] | |
var body: some View { | |
NavigationView { | |
List(countries, id: \.self) { country in | |
NavigationLink( | |
destination: DetailView(country: country), | |
label: { |
This file contains hidden or 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
struct ViewC: View { | |
@Binding var rootActive: Bool | |
var body: some View { | |
VStack { | |
Text("View C") | |
Button("Go to View A") { | |
rootActive = false | |
} |
This file contains hidden or 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
struct ViewB: View { | |
@Binding var rootActive: Bool | |
var body: some View { | |
VStack { | |
Spacer() | |
Text("View B") | |
.font(.largeTitle) | |
This file contains hidden or 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
struct ViewA: View { | |
@State private var isActive: Bool = false | |
var body: some View { | |
VStack { | |
NavigationLink( | |
destination: ViewB(rootActive: $isActive), |
This file contains hidden or 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
return Row( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
Row( | |
children: stars, | |
), | |
FlatButton( | |
child: Text("Clear", style: TextStyle(color: Colors.blue)), | |
onPressed: () { | |
setState(() { |
This file contains hidden or 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
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: Text("Flutter Ratings Widget Demo")), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
Rating((rating) { | |
setState(() { | |
_rating = rating; |
This file contains hidden or 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
class Rating extends StatefulWidget { | |
final int maximumRating; | |
final Function(int) onRatingSelected; | |
Rating(this.onRatingSelected, [this.maximumRating = 5]); | |
@override | |
_Rating createState() => _Rating(); | |
} |
This file contains hidden or 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
return GestureDetector( | |
child: _buildRatingStar(index), | |
onTap: () { | |
print("tapped") | |
}, | |
); |
This file contains hidden or 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
class _Rating extends State<Rating> { | |
Widget _buildRatingStar(int index) { | |
return Icon(Icons.star_border_outlined); | |
} | |
Widget _buildBody() { | |
final stars = List<Widget>.generate(this.widget.maximumRating, (index) { | |
return GestureDetector( | |
child: _buildRatingStar(index), |