1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-09 14:28:51 +00:00
Files
samples/web_embedding/ng-flutter/flutter/lib/main.dart
Brett Morgan 91cb685d1f Publish web_embedding (#1777)
## 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 updated/added relevant documentation (doc comments with `///`).
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-devrel
channel on [Discord].

<!-- Links -->
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[CLA]: https://cla.developers.google.com/
[Discord]: https://github.com/flutter/flutter/wiki/Chat
[Contributors Guide]:
https://github.com/flutter/samples/blob/main/CONTRIBUTING.md


Co-authored-by: Mark Thompson
<2554588+MarkTechson@users.noreply.github.com>
Co-authored-by: David Iglesias <ditman@gmail.com>

Co-authored-by: Mark Thompson <2554588+MarkTechson@users.noreply.github.com>
Co-authored-by: David Iglesias <ditman@gmail.com>
2023-05-06 10:53:17 +10:00

74 lines
1.7 KiB
Dart

// ignore_for_file: avoid_web_libraries_in_flutter
import 'package:flutter/material.dart';
import 'pages/counter.dart';
import 'pages/dash.dart';
import 'pages/text.dart';
import 'src/js_interop.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final ValueNotifier<DemoScreen> _screen = ValueNotifier<DemoScreen>(DemoScreen.counter);
final ValueNotifier<int> _counter = ValueNotifier<int>(0);
final ValueNotifier<String> _text = ValueNotifier<String>('');
late final DemoAppStateManager _state;
@override
void initState() {
super.initState();
_state = DemoAppStateManager(
screen: _screen,
counter: _counter,
text: _text,
);
final export = createDartExport(_state);
// Emit this through the root object of the flutter app :)
broadcastAppEvent('flutter-initialized', export);
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Element embedding',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
useMaterial3: true,
),
home: ValueListenableBuilder<DemoScreen>(
valueListenable: _screen,
builder: (context, value, child) => demoScreenRouter(value),
),
);
}
Widget demoScreenRouter(DemoScreen which) {
switch (which) {
case DemoScreen.counter:
return CounterDemo(counter: _counter);
case DemoScreen.text:
return TextFieldDemo(text: _text);
case DemoScreen.dash:
return DashDemo(text: _text);
}
}
}