You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			42 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Dart
		
	
			
		
		
	
	
			42 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Dart
		
	
import 'package:flutter/material.dart';
 | 
						|
 | 
						|
import 'matrix.dart';
 | 
						|
 | 
						|
class SettingsSwitchListTile extends StatefulWidget {
 | 
						|
  final bool defaultValue;
 | 
						|
  final String storeKey;
 | 
						|
  final String title;
 | 
						|
  final Function(bool)? onChanged;
 | 
						|
 | 
						|
  const SettingsSwitchListTile.adaptive({
 | 
						|
    Key? key,
 | 
						|
    this.defaultValue = false,
 | 
						|
    required this.storeKey,
 | 
						|
    required this.title,
 | 
						|
    this.onChanged,
 | 
						|
  }) : super(key: key);
 | 
						|
 | 
						|
  @override
 | 
						|
  SettingsSwitchListTileState createState() => SettingsSwitchListTileState();
 | 
						|
}
 | 
						|
 | 
						|
class SettingsSwitchListTileState extends State<SettingsSwitchListTile> {
 | 
						|
  @override
 | 
						|
  Widget build(BuildContext context) {
 | 
						|
    return FutureBuilder<bool>(
 | 
						|
      future: Matrix.of(context)
 | 
						|
          .store
 | 
						|
          .getItemBool(widget.storeKey, widget.defaultValue),
 | 
						|
      builder: (context, snapshot) => SwitchListTile.adaptive(
 | 
						|
        value: snapshot.data ?? widget.defaultValue,
 | 
						|
        title: Text(widget.title),
 | 
						|
        onChanged: (bool newValue) async {
 | 
						|
          widget.onChanged?.call(newValue);
 | 
						|
          await Matrix.of(context).store.setItemBool(widget.storeKey, newValue);
 | 
						|
          setState(() {});
 | 
						|
        },
 | 
						|
      ),
 | 
						|
    );
 | 
						|
  }
 | 
						|
}
 |