text
stringlengths 1
372
|
|---|
instead, when the user has entered invalid data,
|
update the state, and pass a new InputDecoration object.
|
<code_start>
|
import 'package:flutter/material.dart';
|
void main() {
|
runApp(const SampleApp());
|
}
|
class SampleApp extends StatelessWidget {
|
/// this widget is the root of your application.
|
const SampleApp({super.key});
|
@override
|
widget build(BuildContext context) {
|
return const MaterialApp(
|
title: 'sample app',
|
home: SampleAppPage(),
|
);
|
}
|
}
|
class SampleAppPage extends StatefulWidget {
|
const SampleAppPage({super.key});
|
@override
|
State<SampleAppPage> createState() => _SampleAppPageState();
|
}
|
class _SampleAppPageState extends State<SampleAppPage> {
|
string? _errorText;
|
string? _getErrorText() {
|
return _errorText;
|
}
|
bool isEmail(String em) {
|
const string emailRegexp =
|
r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|'
|
r'(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|'
|
r'(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$';
|
final RegExp regExp = RegExp(emailRegexp);
|
return regExp.hasMatch(em);
|
}
|
@override
|
widget build(BuildContext context) {
|
return scaffold(
|
appBar: AppBar(title: const Text('Sample app')),
|
body: center(
|
child: TextField(
|
onSubmitted: (text) {
|
setState(() {
|
if (!isemail(text)) {
|
_errorText = 'error: this is not an email';
|
} else {
|
_errorText = null;
|
}
|
});
|
},
|
decoration: InputDecoration(
|
hintText: 'this is a hint',
|
errorText: _getErrorText(),
|
),
|
),
|
),
|
);
|
}
|
}
|
<code_end>
|
<topic_end>
|
<topic_start>
|
flutter plugins
|
<topic_end>
|
<topic_start>
|
interacting with hardware, third party services, and the platform
|
<topic_end>
|
<topic_start>
|
how do i interact with the platform, and with platform native code?
|
flutter doesn’t run code directly on the underlying platform;
|
rather, the dart code that makes up a flutter app is run natively
|
on the device, “sidestepping” the SDK provided by the platform.
|
that means, for example, when you perform a network request in dart,
|
it runs directly in the dart context.
|
you don’t use the android or iOS APIs
|
you normally take advantage of when writing native apps.
|
your flutter app is still hosted in a native app’s
|
ViewController or activity as a view,
|
but you don’t have direct access to this, or the native framework.
|
this doesn’t mean flutter apps can’t interact with those native APIs,
|
or with any native code you have. flutter provides platform channels
|
that communicate and exchange data with the
|
ViewController or activity that hosts your flutter view.
|
platform channels are essentially an asynchronous messaging mechanism
|
that bridges the dart code with the host ViewController
|
or activity and the iOS or android framework it runs on.
|
you can use platform channels to execute a method on the native side,
|
or to retrieve some data from the device’s sensors, for example.
|
in addition to directly using platform channels,
|
you can use a variety of pre-made plugins
|
that encapsulate the native and dart code for a specific goal.
|
for example, you can use a plugin to access
|
the camera roll and the device camera directly from flutter,
|
without having to write your own integration.
|
plugins are found on pub.dev,
|
dart and flutter’s open source package repository.
|
some packages might support native integrations on iOS,
|
or android, or both.
|
if you can’t find a plugin on pub.dev that fits your needs,
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.