rxdart2

import 'package:flutter/material.dart';
import 'package:rxdart/rxdart.dart';
import 'dart:async';

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

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
PublishSubject<String> _textFieldSubject;
@override
void initState() {
_textFieldSubject=PublishSubject<String>();
_textFieldSubject.listen((data)=>print(data));

// TODO: implement initState
super.initState();
}
@override
void dispose() {
// TODO: implement dispose
_textFieldSubject.close();
super.dispose();
}
@override
Widget build(BuildContext context){
return Scaffold(
body: Center(
child: TextField(
onChanged: (value){
_textFieldSubject.add('input:$value');
},
onSubmitted: (value){
_textFieldSubject.add('submit:$value');
},
decoration: InputDecoration(
labelText: 'title',
filled: true,
),
),
),
);
}
}

posted @ 2019-05-07 18:15  braveheart007  阅读(236)  评论(0编辑  收藏  举报