gizmos_settings_screen 0.1.0-nullsafety.1 copy "gizmos_settings_screen: ^0.1.0-nullsafety.1" to clipboard
gizmos_settings_screen: ^0.1.0-nullsafety.1 copied to clipboard

outdated

A Flutter package for displaying in-app settings screens with a native look and feel.

example/lib/main.dart

//
//  gizmos_settings_screen_example
//
//  Copyright (c) 2021, Dave Wood.
//  All rights reserved.
//  Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
//

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'package:gizmos_settings_screen/gizmos_settings_screen.dart';

import 'dog_type.dart';
import 'main_view.dart';

bool useMaterial = !Platform.isIOS;

// Note: useDarkMode could be enhanced to query the system setting
bool useDarkMode = false;

bool defaultSampleBooleanSetting = false;
double defaultDoubleSetting = 0.5;
double defaultDoubleSetting2 = 0.5;
DogType defaultSampleDogType = DogType.CavalierKingCharlesSpaniel;

late SharedPreferences prefs;
late SettingsSkinDelegate skinDelegate;

class ExampleApp extends StatelessWidget {
  // Build
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Gizmos.Dev Settings Screen Example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MainView(title: 'Gizmos.Dev Settings Screen Example'),
    );
  }
}

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  prefs = await SharedPreferences.getInstance();
  if (useDarkMode) {
    skinDelegate = useMaterial ? MaterialDarkSettingsSkin() : CupertinoDarkSettingsSkin();
  } else {
    skinDelegate = useMaterial ? MaterialSettingsSkin() : CupertinoSettingsSkin();
  }

  // Check if we've saved a dog type yet, if not assign the default
  // Note: this is only needed because the way I've set up the DogType enum,
  // it will default to DogType.Other which isn't as good as our desired default
  var savedDogTypeId = prefs.getString('sampleDogType') ?? '';
  if (savedDogTypeId.isEmpty) {
    await prefs.setString('sampleDogType', defaultSampleDogType.id);
  }

  runApp(ExampleApp());
}
19
likes
0
points
15
downloads

Publisher

verified publishergizmos.dev

Weekly Downloads

A Flutter package for displaying in-app settings screens with a native look and feel.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, pedantic

More

Packages that depend on gizmos_settings_screen