Skip to content

Instantly share code, notes, and snippets.

@enzodanjour
Created June 7, 2022 01:05
Show Gist options
  • Select an option

  • Save enzodanjour/c71f293544dc2b9f1aa3c9af9d5d48dd to your computer and use it in GitHub Desktop.

Select an option

Save enzodanjour/c71f293544dc2b9f1aa3c9af9d5d48dd to your computer and use it in GitHub Desktop.
change type
import 'package:flutter/material.dart';
import 'package:testcheck/modelo.dart';
class ControllerIndice extends ChangeNotifier{
List<Modelo> modelo =[Modelo(texto: ' show do milh', habilitado: false),
Modelo(texto: ' show do milh', habilitado: false)];
void updateState(int index, bool value){
modelo[index].habilitado = value;
print('mudou valor');
notifyListeners();
}
}
import 'package:flutter/material.dart';
import 'package:testcheck/controller/controller_indice.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
ControllerIndice indice = ControllerIndice();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: AnimatedBuilder(
animation: indice,
builder: (context, value) {
return ListView.builder(
shrinkWrap: true,
itemCount: indice.modelo.length,
itemBuilder: (context, index) {
return CheckboxListTile(
title: Text('${indice.modelo[index].texto}'),
value: indice.modelo[index].habilitado,
onChanged: (value) {
indice.updateState(index,value!);
},
);
},
);
}),
);
}
}
class Modelo {
String texto;
bool habilitado;
Modelo({
required this.texto,
required this.habilitado,
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment