surf_logger 1.1.0 icon indicating copy to clipboard operation
surf_logger: ^1.1.0 copied to clipboard

Logger for Dart & Flutter

example/lib/main.dart

// Copyright (c) 2019-present,  SurfStudio LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import 'package:flutter/material.dart';
import 'package:surf_logger/surf_logger.dart';

void main() {
  _initLogger();
  runApp(MyApp());
}

void _initLogger() {
  Logger.addStrategy(DebugLogStrategy());
}

class MyApp extends StatelessWidget {
  MyApp({Key? key}) : super(key: key) {
    Logger.d('MyApp constructor');
  }

  @override
  Widget build(BuildContext context) {
    Logger.d('MyApp build');
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  final String title;

  MyHomePage({
    required this.title,
    Key? key,
  }) : super(key: key) {
    Logger.d('MyHomePage constructor');
  }

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  _MyHomePageState() {
    Logger.d('MyHomePageState constructor');
  }

  @override
  void initState() {
    Logger.d('MyHomePageState initState');
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    Logger.d('MyHomePageState build');
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }

  void _incrementCounter() {
    Logger.d('counter value = $_counter before setState');
    setState(() {
      _counter++;
    });
    Logger.d('counter value = $_counter after setState');
  }
}