intent_ns 2.0.0 copy "intent_ns: ^2.0.0" to clipboard
intent_ns: ^2.0.0 copied to clipboard

PlatformAndroid
unlisted

A null-safe fork of the intent package.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:intent_ns/intent.dart' as android_intent;
import 'package:intent_ns/action.dart' as android_action;
import 'dart:async' show StreamController;
import 'dart:io';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late MyAppDataModel _myAppDataModel;

  @override
  void initState() {
    _myAppDataModel = MyAppDataModel();
    _myAppDataModel.inputClickState.add([]);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text(
            'Plugin Example App',
            style: TextStyle(
              color: Colors.black,
            ),
          ),
          centerTitle: true,
          backgroundColor: Colors.cyanAccent,
        ),
        body: Center(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              StreamBuilder<List<String>>(
                initialData: [],
                stream: _myAppDataModel.outputResult,
                builder: (context, snapshot) => Padding(
                  padding: EdgeInsets.only(
                    left: 8,
                    right: 8,
                    top: 12,
                    bottom: 24,
                  ),
                  child: snapshot.hasData
                      ? snapshot.data!.isNotEmpty
                          ? ClipRRect(
                              borderRadius: BorderRadius.circular(24),
                              child: Image.file(
                                File(snapshot.data![0]),
                                fit: BoxFit.cover,
                                width: MediaQuery.of(context).size.width * .75,
                                height:
                                    MediaQuery.of(context).size.height * .35,
                              ),
                            )
                          : Center()
                      : CircularProgressIndicator(),
                ),
              ),
              ElevatedButton(
                style: ElevatedButton.styleFrom(
                  primary: Colors.cyanAccent,
                  elevation: 16,
                ),
                onPressed: () => android_intent.Intent()
                  ..setAction(android_action.Action.ACTION_IMAGE_CAPTURE)
                  ..startActivityForResult().then(
                    (data) => print(data),
                    onError: (e) => print(e.toString()),
                  ),
                child: Text('Intent'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class MyAppDataModel {
  StreamController<List<String>> _streamController =
      StreamController<List<String>>.broadcast();

  Sink<List<String>> get inputClickState => _streamController;

  Stream<List<String>> get outputResult =>
      _streamController.stream.map((data) => data);

  dispose() => _streamController.close();
}
1
likes
120
pub points
34%
popularity

Publisher

verified publishergroovinchip.dev

A null-safe fork of the intent package.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on intent_ns