Created
May 28, 2020 19:07
-
-
Save ishaquehassan/2ffc2850e7157dc64529126da608f854 to your computer and use it in GitHub Desktop.
Demo Code for handling toggle of switches in singles screen
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'; | |
import 'package:flutter/widgets.dart'; | |
class ListPage extends StatelessWidget{ | |
@override | |
Widget build(_) => ListView.builder( | |
itemCount: 2, | |
itemBuilder: (_,itemPosition)=>_ItemView(index: itemPosition) | |
); | |
} | |
class _ItemView extends StatefulWidget{ | |
final int index; | |
const _ItemView({Key key,@required this.index}) : super(key: key); | |
@override | |
__ItemViewState createState() => __ItemViewState(); | |
} | |
class __ItemViewState extends State<_ItemView> { | |
bool value = false; | |
@override | |
Widget build(_) => ListTile( | |
title: Text("Switch Widget ${widget.index}"), | |
trailing: Switch( | |
value: value, | |
onChanged: (newValue)=>setState((){ | |
value = newValue; | |
}), | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment