Created
June 7, 2022 01:05
-
-
Save enzodanjour/c71f293544dc2b9f1aa3c9af9d5d48dd to your computer and use it in GitHub Desktop.
change type
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
| 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(); | |
| } | |
| } |
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
| 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!); | |
| }, | |
| ); | |
| }, | |
| ); | |
| }), | |
| ); | |
| } | |
| } |
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 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