Skip to main content

spring_boot_starter_flutter 0.3.0 copy "spring_boot_starter_flutter: ^0.3.0" to clipboard
spring_boot_starter_flutter: ^0.3.0 copied to clipboard

Spring Boot for Flutter apps: SpringApplicationWidget starts the app, beans in widgets (context.bean, generated getters, SpringStatelessWidget), lifecycle, platform profiles.

example/example.dart

// The Flutter counter on spring_boot_starter_flutter, in one file.
//
// In an application the generator writes the beans: annotate the classes
// (`@SpringBootApplication()` on main, `@ChangeNotifierComponent()` on
// Counter) and run `dart run build_runner build` — see README.md. Here the
// bean module is written by hand, so the example runs without code
// generation.
import 'package:flutter/material.dart';
import 'package:spring_boot_starter_flutter/spring_boot_starter_flutter.dart';

/// The count: state in a bean instead of a `State`, so any widget (and any
/// service) can read and change it.
class Counter extends ChangeNotifier {
  int _value = 0;

  /// The current count.
  int get value => _value;

  /// Adds one and tells the listeners.
  void increment() {
    _value++;
    notifyListeners();
  }
}

/// What the generator writes for the annotated classes of an application.
SpringApplication application() => SpringApplication([
  BeanModule('example', [
    BeanDefinition<Counter>(
      name: 'counter',
      types: const [Counter],
      create: (_) => Counter(),
    ),
  ]),
]);

void main() => runApp(
  // Starts the application (a splash screen meanwhile, a report when it
  // fails) and gives its beans to every widget below.
  SpringApplicationWidget(
    application: application,
    child: const MaterialApp(home: CounterPage()),
  ),
);

/// The page of the template; stateless, the count is the `Counter` bean.
class CounterPage extends StatelessWidget {
  /// Creates the page.
  const CounterPage({super.key});

  @override
  Widget build(BuildContext context) {
    // Any bean by type.
    final counter = context.bean<Counter>();
    return Scaffold(
      appBar: AppBar(title: const Text('spring_boot_starter_flutter')),
      body: Center(
        child: ListenableBuilder(
          listenable: counter,
          builder: (context, _) => Text(
            '${counter.value}',
            style: Theme.of(context).textTheme.headlineMedium,
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: counter.increment,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}
0
likes
0
points
404
downloads

Publisher

verified publisherfarum-azula.org

Weekly Downloads

Spring Boot for Flutter apps: SpringApplicationWidget starts the app, beans in widgets (context.bean, generated getters, SpringStatelessWidget), lifecycle, platform profiles.

Repository (GitHub)
View/report issues

Topics

#dependency-injection #flutter #spring

License

unknown (license)

Dependencies

flutter, flutter_localizations, spring_boot_dart, spring_boot_starter_logging

More

Packages that depend on spring_boot_starter_flutter