Skip to content

Instantly share code, notes, and snippets.

@ishaquehassan
Created May 28, 2020 19:07
Show Gist options
  • Save ishaquehassan/2ffc2850e7157dc64529126da608f854 to your computer and use it in GitHub Desktop.
Save ishaquehassan/2ffc2850e7157dc64529126da608f854 to your computer and use it in GitHub Desktop.
Demo Code for handling toggle of switches in singles screen
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