Skip to main content

spring_boot_starter_flutter 0.3.2 copy "spring_boot_starter_flutter: ^0.3.2" to clipboard
spring_boot_starter_flutter: ^0.3.2 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 as a Spring Boot application: the count is a bean,
// widgets get beans by type, and the generator writes the rest
// (example.spring.dart, from `dart run build_runner build`).
import 'package:flutter/material.dart';
import 'package:spring_boot_starter_flutter/spring_boot_starter_flutter.dart';

import 'example.spring.dart';

/// The count: state in a bean instead of a `State`, so any widget (and any
/// service) can read and change it. The generator makes it a
/// `ChangeNotifier` that notifies after every method.
@ChangeNotifierComponent()
class Counter {
  int _value = 0;

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

  /// Adds one.
  void increment() => _value++;
}

@SpringBootApplication()
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: () => springApplication,
    child: const MaterialApp(home: CounterPage()),
  ),
);

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

  @override
  Widget build(BuildContext context) {
    final (counter,) = beans;
    return Scaffold(
      appBar: AppBar(title: const Text('spring_boot_starter_flutter')),
      body: const Center(child: CounterText()),
      // Only calls a method: a tap does not rebuild the page.
      floatingActionButton: FloatingActionButton(
        onPressed: counter.increment,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}

/// Reads `counter.value`, so it rebuilds after every increment.
class CounterText extends SpringStatelessWidget<(Counter,)> {
  /// Creates the text.
  const CounterText({super.key});

  @override
  Widget build(BuildContext context) {
    final (counter,) = beans;
    return Text(
      '${counter.value}',
      style: Theme.of(context).textTheme.headlineMedium,
    );
  }
}
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