1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 22:09:06 +00:00
Files
samples/material_3_demo/lib/main.dart
Eric Windmill 2999d738b8 Dart 3.9 / Flutter 3.35 [first LLM release] (#2714)
I got carried away with Gemini and basically rewrote CI and the release
process for the new LLM reality. This work was largely completed by
Gemini.

- Bump all SDK versions to the current beta (3.9.0-0)
- Run `flutter channel beta`
- Wrote `ci_script.dart` to replace the bash scripts
- Converted repository to pub workspace #2499 
- Added llm.md and release.md
- Added redirect for deprecated Samples Index

## Pre-launch Checklist

- [x] I read the [Flutter Style Guide] _recently_, and have followed its
advice.
- [x] I signed the [CLA].
- [x] I read the [Contributors Guide].
- [x] I have added sample code updates to the [changelog].
- [x] I updated/added relevant documentation (doc comments with `///`).
2025-08-14 12:26:24 -07:00

108 lines
3.1 KiB
Dart

// Copyright 2021 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'src/constants.dart';
import 'src/home.dart';
void main() async {
runApp(const App());
}
class App extends StatefulWidget {
const App({super.key});
@override
State<App> createState() => _AppState();
}
class _AppState extends State<App> {
bool _useMaterial3 = true;
ThemeMode _themeMode = ThemeMode.system;
ColorSeed _colorSelected = ColorSeed.baseColor;
ColorImageProvider _imageSelected = ColorImageProvider.leaves;
ColorScheme? _imageColorScheme = const ColorScheme.light();
ColorSelectionMethod _colorSelectionMethod = ColorSelectionMethod.colorSeed;
bool get _useLightMode => switch (_themeMode) {
ThemeMode.system =>
View.of(context).platformDispatcher.platformBrightness ==
Brightness.light,
ThemeMode.light => true,
ThemeMode.dark => false,
};
void _handleBrightnessChange(bool useLightMode) {
setState(() {
_themeMode = useLightMode ? ThemeMode.light : ThemeMode.dark;
});
}
void _handleMaterialVersionChange() {
setState(() {
_useMaterial3 = !_useMaterial3;
});
}
void _handleColorSelect(int value) {
setState(() {
_colorSelectionMethod = ColorSelectionMethod.colorSeed;
_colorSelected = ColorSeed.values[value];
});
}
void _handleImageSelect(int value) {
final String url = ColorImageProvider.values[value].url;
ColorScheme.fromImageProvider(provider: NetworkImage(url)).then((
newScheme,
) {
setState(() {
_colorSelectionMethod = ColorSelectionMethod.image;
_imageSelected = ColorImageProvider.values[value];
_imageColorScheme = newScheme;
});
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Material 3',
themeMode: _themeMode,
theme: ThemeData(
colorSchemeSeed:
_colorSelectionMethod == ColorSelectionMethod.colorSeed
? _colorSelected.color
: null,
colorScheme: _colorSelectionMethod == ColorSelectionMethod.image
? _imageColorScheme
: null,
useMaterial3: _useMaterial3,
brightness: Brightness.light,
),
darkTheme: ThemeData(
colorSchemeSeed:
_colorSelectionMethod == ColorSelectionMethod.colorSeed
? _colorSelected.color
: _imageColorScheme!.primary,
useMaterial3: _useMaterial3,
brightness: Brightness.dark,
),
home: Home(
useLightMode: _useLightMode,
useMaterial3: _useMaterial3,
colorSelected: _colorSelected,
imageSelected: _imageSelected,
handleBrightnessChange: _handleBrightnessChange,
handleMaterialVersionChange: _handleMaterialVersionChange,
handleColorSelect: _handleColorSelect,
handleImageSelect: _handleImageSelect,
colorSelectionMethod: _colorSelectionMethod,
),
);
}
}