Skip to content

Instantly share code, notes, and snippets.

View azamsharp's full-sized avatar

Mohammad Azam azamsharp

View GitHub Profile
extension View {
func toAnyView() -> AnyView {
return AnyView(self)
}
}
enum Route {
case detail(String)
case aboutUs
case addCountry
@azamsharp
azamsharp / .swift
Last active January 14, 2021 01:47
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: {
@azamsharp
azamsharp / .swift
Last active December 31, 2020 19:09
struct ViewC: View {
@Binding var rootActive: Bool
var body: some View {
VStack {
Text("View C")
Button("Go to View A") {
rootActive = false
}
struct ViewB: View {
@Binding var rootActive: Bool
var body: some View {
VStack {
Spacer()
Text("View B")
.font(.largeTitle)
struct ViewA: View {
@State private var isActive: Bool = false
var body: some View {
VStack {
NavigationLink(
destination: ViewB(rootActive: $isActive),
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
children: stars,
),
FlatButton(
child: Text("Clear", style: TextStyle(color: Colors.blue)),
onPressed: () {
setState(() {
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;
class Rating extends StatefulWidget {
final int maximumRating;
final Function(int) onRatingSelected;
Rating(this.onRatingSelected, [this.maximumRating = 5]);
@override
_Rating createState() => _Rating();
}
@azamsharp
azamsharp / .swift
Last active December 28, 2020 18:10
return GestureDetector(
child: _buildRatingStar(index),
onTap: () {
print("tapped")
},
);
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),